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:
Bob Nystrom
2015-01-14 05:36:42 +00:00
parent d031d0a77d
commit 54ef9bbc73
8 changed files with 124 additions and 61 deletions
+18
View File
@@ -0,0 +1,18 @@
var foo = "variable"
class Foo {
foo { "method" }
method {
IO.print(foo)
}
static foo { "class method" }
static classMethod {
IO.print(foo)
}
}
(new Foo).method // expect: method
Foo.classMethod // expect: class method