LocalSameAsGlobal and "base"

Report problems with documented functionality
Eidola
Posts: 22
Joined: 25 Aug 2016, 14:44

LocalSameAsGlobal and "base"

22 Oct 2018, 06:36

I recently upgraded to v1.1.30.00 and have enabled all the warnings and seem unable to fix the following warning:

Warning: This local variable has the same name as a global variable.
Specifically: base

Right now I get a TON of these warnings as I have created a collection of objects, most of which inherit from a common base object... no, it isn't named "base", I learned that lesson already lol... and then use 'base' to forward __New and __Delete calls.

However, it seems there is an issue somewhere with 'base' and this warning. Take the following simple code, for example:

Code: Select all

 
#NoEnv
#Warn LocalSameAsGlobal, StdOut

Class One {
	__New() {
		OutputDebug % "New One"
	}
}

Class Two extends One {
	_error := 0
	
	__New() {
		local test
		OutputDebug % "New Two"
		base.__New()
	}
}

test := new Two()
When this code is run a warning about 'base' will be emitted to StdOut:

WarnTest.ahk (11) : ==> Warning: This local variable has the same name as a global variable.
Specifically: base (in function Two.__Init)

However, if the '_error := 0' line is commented out and then the script run again the warning will not be emitted. It appears the issue is when the instance variables are being defined in the default __Init function... so how can I fix this issue?

Is there some way to have the #LocalSameAsGlobal warning system ignore 'base', or is there a way I can fix this issue without just disabling the entire warning altogether?

I did search Google and the forums for "LocalSameAsGlobal base" but didn't really find anything that helped... thanks for any insights! :)

~Eidola
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: LocalSameAsGlobal and "base"

31 Oct 2018, 01:09

Your __New method is assume-global because it declares a local variable. As a result, base is global. (On a side note, any assignment to this global variable would potentially break your __New method.) Either declare local base or avoid assume-global.

This is one reason for base to become a true reserved word in v2 (but it's not a bug).
Eidola
Posts: 22
Joined: 25 Aug 2016, 14:44

Re: LocalSameAsGlobal and "base"

17 Nov 2018, 03:24

Thanks for the reply Lexikos. However, given the special nature of the global base variable might you consider adding an option to the #LocalSameAsGlobal directive to suppress the warning for this particular situation?

My only use of base is as recommended and I don't declare or otherwise use the name base for any other code... so having to declare it as a local variable in every method I use just seems somewhat kludgy to me. Suppressing the warning for base would just be a nice tidy option for this particular directive, especially if people are actually using base as recommended. :)
Eidola
Posts: 22
Joined: 25 Aug 2016, 14:44

Re: LocalSameAsGlobal and "base"

17 Nov 2018, 03:29

Sorry for posting this in the bug forum, I can see how it isn't a bug... just given our previous discussions about base I thought the #LocalSameAsGlobal directive would suppress warnings for base inside methods due to the special nature of the base global variable.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 24 guests