Add support for "nonlocal" (capitalized) names, and change how variable lookup works.
Inside a method, all local variable lookup stops at the method boundary. In other words, methods, do not close over outer local variables. If a name is not found inside a method and is lowercase, it's a method on this. If it's capitalized, it's a global variable.
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