[a118] Gui GetPos() warning for output params Topic is solved

Report problems with documented functionality
SAbboushi
Posts: 214
Joined: 08 Dec 2014, 22:13

[a118] Gui GetPos() warning for output params

20 Jul 2020, 12:46

Code: Select all

MyGui := Gui.New()
MyGui.GetPos( X, Y, Width, Height )

/*
Warning:  This variable appears to never be assigned a value.

Specifically: global X

	Line#
	001: MyGui := Gui.New()
--->	002: MyGui.GetPos( X, Y, Width, Height )
User avatar
Tigerlily
Posts: 322
Joined: 04 Oct 2018, 22:31

Re: [a118] Gui GetPos() warning for output params

20 Jul 2020, 15:17

@SAbboushi
you must declare the variables first, this will get rid of the warning:

Code: Select all

; X := "", Y := "", Width := "", Height := ""
X := Y := Width := Height := ""
MyGui := Gui.New()
MyGui.GetPos( X, Y, Width, Height )
-TL
SAbboushi
Posts: 214
Joined: 08 Dec 2014, 22:13

Re: [a118] Gui GetPos() warning for output params

20 Jul 2020, 16:17

I'm not aware of a V2 requirement to initialize output variables. If you're aware of supporting documentation, can you please provide a link?
swagfag
Posts: 3900
Joined: 11 Jan 2017, 17:59

Re: [a118] Gui GetPos() warning for output params

20 Jul 2020, 16:31

@aseiot wrote about this earlier https://www.autohotkey.com/boards/viewtopic.php?p=342939#p342939
a112 wrote:Enabled #Warn UseUnset by default - to be converted to a continuable error at some point.

u can
  • disable the warnings - pointless, merely delaying, since theyll be baked in eventually
  • X := Y := Width := Height := "" - this is kinda annoying having to write before each ByRef param usage
maybe disable this for ByRef params? or split ByRef(see c#, in/out/ref)?
SAbboushi
Posts: 214
Joined: 08 Dec 2014, 22:13

Re: [a118] Gui GetPos() warning for output params

20 Jul 2020, 17:05

swagfag wrote:
20 Jul 2020, 16:31
@aseiot wrote about this earlier https://www.autohotkey.com/boards/viewtopic.php?p=342939#p342939
Thanks - missed that.

If I'm understanding the thread correctly, lexikos believed [a118] "fixed" that.
And if I'm understanding the documentation correctly, I believe the variables in GetPos() are [references to variables that are used as output variables in a non-dynamic function call] and therefore the warning is not compliant with the doc:
Changed #Warn UseUnset to also warn at load time if possible.
  • Flags the first reference to each variable which is not used in a direct non-dynamic assignment or as an output var/ByRef parameter of a non-dynamic function call.
swagfag
Posts: 3900
Joined: 11 Jan 2017, 17:59

Re: [a118] Gui GetPos() warning for output params

20 Jul 2020, 17:13

.GetPos() is a method, not a function
lexikos
Posts: 6968
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [a118] Gui GetPos() warning for output params

20 Jul 2020, 22:06

Even if you call the method a function, all method calls are dynamic. This is not a bug, merely a shortcoming of the current ByRef syntax (having the variable reference passed implicitly) in combination with load-time detection of assignments. It is not possible to detect at load time whether the parameter of a dynamic call is ByRef. As I mentioned in the other thread, I am not finished with it yet.
SAbboushi wrote:If I'm understanding the thread correctly, lexikos believed [a118] "fixed" that.
You are not understanding the thread correctly. aseiot posted a bunch of different issues, some related, some unrelated. I specifically noted which issues were fixed, and this was not one of them. (I didn't specifically say this isn't a bug, but I implied it.)
swagfag wrote:disable the warnings - pointless, merely delaying, since theyll be baked in eventually
I haven't updated the #Warn UseUnset documentation yet - it is only the documented part that will be replaced with a runtime error. That is, there will be a runtime error when you attempt to access an uninitialized variable. The load time warnings will take the place of #Warn UseUnset, and will be optional. They might become positional or scoped, so you can disable the warning for a specific section of code.
SAbboushi
Posts: 214
Joined: 08 Dec 2014, 22:13

Re: [a118] Gui GetPos() warning for output params

21 Jul 2020, 09:19

Thanks - appreciate the clarifications/education.
SAbboushi
Posts: 214
Joined: 08 Dec 2014, 22:13

Re: [a118] Gui GetPos() warning for output params

21 Jul 2020, 10:09

@Tigerlily
Thanks for your help. You said exactly what lexikos did:
You can avoid it by initializing the variable before passing it ByRef
lexikos
Posts: 6968
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [a118] Gui GetPos() warning for output params  Topic is solved

01 Aug 2020, 04:49

This does not cause a warning in v2.0-a119.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 11 guests