Faulty restoration of super global variables after for loop Topic is solved

Discuss the future of the AutoHotkey language
Helgef
Posts: 3192
Joined: 17 Jul 2016, 01:02
Contact:

Faulty restoration of super global variables after for loop

12 Jun 2018, 12:39

Example,

Code: Select all

k(){
	for k in [1]
		(1)
}
global k := 1
k
msgbox k ; blank
compare to

Code: Select all

global k := 1
k(){
	for k in [1]
		(1)
}
k
msgbox k ; 1
and

Code: Select all

k(){
	global
	for k in [1]
		(1)
}
k := 1
k
msgbox k ; 1
First observed here (see the spoiler).

Cheers.
iseahound
Posts: 307
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Faulty restoration of super global variables after for loop

12 Jun 2018, 16:31

What does (1) do?
swagfag
Posts: 1231
Joined: 11 Jan 2017, 17:59

Re: Faulty restoration of super global variables after for loop

12 Jun 2018, 17:08

its just a garbage forced expression, evaluating to true, then discarding the result as there's nothing to capture it, intended to make the forloop run without the need for calling actual function or placing braces

id rewrite it tbh:

Code: Select all

fun(){
	for var in [1] {
	}
}
global var := 1
fun()
msgbox(var) ; blank

Code: Select all

global var := 1
fun(){
	for var in [1] {
	}
}
fun()
msgbox(var) ; 1

Code: Select all

fun(){
	global
	for var in [1] {
	}
}
var := 1
fun()
msgbox(var) ; 1
iseahound
Posts: 307
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Faulty restoration of super global variables after for loop

12 Jun 2018, 17:29

That is very cool. Appreciate the explanation. It might be better to use (0) instead to denote the null process.

EDIT: or just continue
lexikos
Posts: 6176
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Faulty restoration of super global variables after for loop  Topic is solved

12 Jun 2018, 22:44

Fixed in v2.0-a097.

The bug applied to all aliases; that is: ByRef, free variables (variables captured by a closure, both in a closure and in the outer function), and "local references" to super-global variables. The last one is an implementation hack; the variable references are resolved when they are encountered, so a later stage converts each undeclared local variable to an alias if it corresponds to a super-global.
Helgef
Posts: 3192
Joined: 17 Jul 2016, 01:02
Contact:

Re: Faulty restoration of super global variables after for loop

13 Jun 2018, 11:39

Thanks for the updates.

Sorry for the confusing examples.
id rewrite it tbh:
yes, that is better.

Cheers.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 3 guests