Closed
Description
Variables declared in a finally block cause an assertion error in the CPS builder, because one variable is added to the environment multiple times.
This is the assertion that fails:
void extend(Local element, ir.Primitive value) {
// Assert that the name is not already in the environment. `null` is used
// as the name of anonymous variables.
assert(!variable2index.containsKey(element));
if (element != null) variable2index[element] = index2variable.length;
index2variable.add(element);
index2value.add(value);
}
There are a bunch of tests that fail in checked-mode because of this; here is a minimal one:
main() {
try {
print("fdg");
} finally {
var x = 12345678;
print(x);
}
}
The variable may be assigned different indices because of different environment sizes at entry points to the finally. I can't see an easy fix to this short of wrapping all variable elements in a "finally element" so different copies of the variable can be distinguished.
The issue should go away when we introduce first-class finally to the IR. I'm not sure if it's worth fixing in the current form.