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:
@@ -1,17 +0,0 @@
|
||||
// TODO: Is this right? Shouldn't it resolve to this.local?
|
||||
var foo = null
|
||||
|
||||
{
|
||||
var local = "local"
|
||||
class Foo {
|
||||
construct new() {}
|
||||
|
||||
method {
|
||||
System.print(local)
|
||||
}
|
||||
}
|
||||
|
||||
foo = Foo.new()
|
||||
}
|
||||
|
||||
foo.method // expect: local
|
||||
@@ -1,13 +0,0 @@
|
||||
// TODO: Is this right? Shouldn't it resolve to this.local?
|
||||
{
|
||||
var local = "local"
|
||||
class Foo {
|
||||
construct new() {}
|
||||
|
||||
method {
|
||||
System.print(local)
|
||||
}
|
||||
}
|
||||
|
||||
Foo.new().method // expect: local
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user