fix: resolve local names in methods as self sends instead of upvalues

When a method references a name that exists as a local variable outside the method boundary, the compiler now correctly treats it as a self send rather than closing over the outer local. This fixes the closure resolution logic in `findUpvalue` to stop searching for upvalues when hitting a method boundary, unless the name starts with '_' indicating a static field access. The change removes two incorrect test cases that expected outer local closure behavior and adds a new test verifying that both instance and static methods resolve local names to their own methods.
This commit is contained in:
Bob Nystrom
2015-10-05 14:44:51 +00:00
parent 27d6176f40
commit ddc3ec855e
4 changed files with 29 additions and 33 deletions
@@ -0,0 +1,22 @@
{
var foo = "variable"
class Foo {
construct new() {}
foo { "method" }
method {
System.print(foo)
}
static foo { "class method" }
static classMethod {
System.print(foo)
}
}
Foo.new().method // expect: method
Foo.classMethod // expect: class method
}