Only close an upvalue for a local if there actually is one for it.

This commit is contained in:
Bob Nystrom
2015-10-08 08:06:29 -07:00
parent 24cbb7f399
commit 8980d34ee5
3 changed files with 49 additions and 17 deletions
@@ -0,0 +1,19 @@
// This is a regression test. When closing upvalues for discarded locals, it
// wouldn't make sure it discarded the upvalue for the correct stack slot.
//
// Here we create two locals that can be closed over, but only the first one
// actually is. When "b" goes out of scope, we need to make sure we don't
// prematurely close "a".
var closure
{
var a = "a"
{
var b = "b"
closure = Fn.new { a }
if (false) Fn.new { b }
}
System.print(closure.call()) // expect: a
}