Add a closure test.

This commit is contained in:
Bob Nystrom
2014-04-19 17:48:06 -07:00
parent 09c707e16a
commit 3087daaece
3 changed files with 19 additions and 1 deletions

View File

@ -1726,6 +1726,14 @@ static void name(Compiler* compiler, bool allowAssignment)
return;
}
// TODO: The fact that we walk the entire scope chain up to global before
// interpreting a name as an implicit "this" call means that surrounding
// names shadow ones in the class. This is good for things like globals.
// (You wouldn't want `new Fiber` translating to `new this.Fiber`, but may
// not be what we want for other names.) One option is to make capitalized
// names *always* global, and then a lowercase name will become on an
// implicit this if it's not a local in the nearest enclosing class.
// Otherwise, if we are inside a class, it's a call with an implicit "this"
// receiver.
ClassCompiler* classCompiler = getEnclosingClass(compiler);

View File

@ -15,4 +15,3 @@
}
// TODO: Maximum number of closed-over variables (directly and/or indirect).
// TODO: Shadow variable used in closure.

View File

@ -0,0 +1,11 @@
{
var foo = "closure"
new Fn {
{
IO.print(foo) // expect: closure
var foo = "shadow"
IO.print(foo) // expect: shadow
}
IO.print(foo) // expect: closure
}.call
}