Closure variables do not properly update
Opened this issue · 0 comments
ProjectMoon commented
Simple example:
def outer() {
var x = 0;
def inner1() {
x = x + 1;
return x;
}
def inner2() {
x = x + 2;
return x;
}
var l = [];
l[0] = inner1;
l[1] = inner2;
return l;
}
var fns = outer();
println(fns[0]());
println(fns[1]());
Expected result would be to print 1, then 3. Instead it prints 0 and 0. The reason is due to ScopeManager.putVariable
erroneously updating the field into the temp fields map, which is considered lower priority than the "permanent" fields. Simplest fix is to update the permanent fields map when a closure scope is found for the given identifier.
Comment says "this or condition prevents namespaced references in functions from going to the temp fields map." Not sure if it even needs to exist anymore, since namespaces aren't really a thing.