feat: stop closure upvalue search at method boundaries and treat capitalized names as globals
Modify `findUpvalue` in the compiler to return -1 when the enclosing function is a method, preventing closures from capturing outer local variables. Add a new `nonlocal` variable resolution path that treats capitalized identifiers as global variables rather than method receivers. Update existing test files to use capitalized global names and add new test cases for nonlocal assignment, duplicate nonlocal declarations, block scoping, and method-local variable shadowing.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
var f = null
|
||||
var F = null
|
||||
|
||||
class Foo {
|
||||
method(param) {
|
||||
f = new Fn {
|
||||
F = new Fn {
|
||||
IO.print(param)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(new Foo).method("param")
|
||||
f.call // expect: param
|
||||
F.call // expect: param
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
var global = "global"
|
||||
// TODO: Forward reference to global declared after use.
|
||||
|
||||
new Fn {
|
||||
IO.print(global) // expect: global
|
||||
}.call
|
||||
@@ -1,15 +0,0 @@
|
||||
var global = "global"
|
||||
// TODO: Forward reference to global declared after use.
|
||||
|
||||
class Foo {
|
||||
method {
|
||||
IO.print(global)
|
||||
}
|
||||
|
||||
static classMethod {
|
||||
IO.print(global)
|
||||
}
|
||||
}
|
||||
|
||||
(new Foo).method // expect: global
|
||||
Foo.classMethod // expect: global
|
||||
Reference in New Issue
Block a user