Implicitly define nonlocal names.
If a capitalized name cannot be resolved, a new top-level variable with its name is implicitly declared. If a real definition is not found later, a compile time error is raised. Mutual recursion at the top level works now! Fix #101. Fix #106.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
class Foo {
|
||||
static bar { new Bar }
|
||||
}
|
||||
|
||||
class Bar {
|
||||
static foo { new Foo }
|
||||
}
|
||||
|
||||
IO.print(Foo.bar) // expect: instance of Bar
|
||||
IO.print(Bar.foo) // expect: instance of Foo
|
||||
@@ -0,0 +1,3 @@
|
||||
IO.print(Foo) // expect: null
|
||||
var Foo = "value"
|
||||
IO.print(Foo) // expect: value
|
||||
@@ -0,0 +1,7 @@
|
||||
var fn = new Fn {
|
||||
IO.print(Foo)
|
||||
IO.print(Bar)
|
||||
}
|
||||
|
||||
// expect error line 7
|
||||
// expect error line 7
|
||||
@@ -1,5 +1,4 @@
|
||||
var Global = "global"
|
||||
// TODO: Forward reference to global declared after use.
|
||||
|
||||
new Fn {
|
||||
IO.print(Global) // expect: global
|
||||
@@ -0,0 +1,7 @@
|
||||
var f = new Fn {
|
||||
IO.print(Global)
|
||||
}
|
||||
|
||||
var Global = "global"
|
||||
|
||||
f.call // expect: global
|
||||
@@ -1,5 +1,4 @@
|
||||
var Global = "global"
|
||||
// TODO: Forward reference to global declared after use.
|
||||
|
||||
class Foo {
|
||||
method {
|
||||
@@ -0,0 +1,14 @@
|
||||
class Foo {
|
||||
method {
|
||||
IO.print(Global)
|
||||
}
|
||||
|
||||
static classMethod {
|
||||
IO.print(Global)
|
||||
}
|
||||
}
|
||||
|
||||
var Global = "global"
|
||||
|
||||
(new Foo).method // expect: global
|
||||
Foo.classMethod // expect: global
|
||||
Reference in New Issue
Block a user