forked from Mirror/wren
Fix closures in methods.
A local name inside a method should always resolve to a self send even if there is a local variable with that name outside of the method.
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
|
||||
}
|
||||
22
test/language/variable/local_outside_method.wren
Normal file
22
test/language/variable/local_outside_method.wren
Normal file
@ -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