Region of local mutable variables disagrees with llvm backend semantics
Consider the following program:
def test3(): Int = {
val f = {
var l = 1;
box { l }
}
f()
}
def main() = println(test3())
It should print 1, which it does. Except when run with effekt --backend=llvm --no-optimize, where it prints
105971318358032, some garbage value. The local mutable variable l escapes its region, which in the llvm backend operationally is only until the end of the local compound statement (block).
Shouldn't this code be illegal? f: () -> Int at { l } right? And test3's body does not have access to l, so it shouldn't be able to use it. Thus, the code should be rejected.
I also see the argument that the local variable gets stored in the closest enclosing function (so the closest lambda or def). Then the LLVM backend needs to allocate it into test3's region