Skip to content

Commit

Permalink
Fix "effectively final" computation in a switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene Gleyzer committed Jul 18, 2023
1 parent 7776632 commit 60f1d4d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Expand Up @@ -665,9 +665,14 @@ protected CaseBlockContext(SwitchContext ctxOuter)
@Override
public Context exit()
{
// don't contribute; the break statement has already registered the "Statement.Break"
// info that will be processed at the end of Statement.validate() logic
return getOuterContext();
Context ctxOuter = getOuterContext();

// promote the assignments, but not narrowed types; the break statement has already
// registered the "Statement.Break" info that will be processed at the end of
// Statement.validate() logic
promoteAssignments(ctxOuter);

return ctxOuter;
}
}

Expand Down
23 changes: 15 additions & 8 deletions manualTests/src/main/x/TestSimple.x
Expand Up @@ -2,15 +2,22 @@ module TestSimple.examples.org {
@Inject Console console;

void run() {
String[] strings = ["abc", "def"];

Test<String> t = new Test(strings);
String[] filtered = t.filter(s -> s.indexOf("e")).toArray(Constant); // that used to fail at RT
console.print(filtered);
}

service Test<Element>(Collection<Element> underlying)
implements Collection<Element>
delegates Collection(underlying) {
Int test(Int x) {
switch (x) {
case 0:
return 0;

case 1:
Int bug = x + 1;
function Int (Int) supply = i -> {
return bug + i; // "bug" used to be not "effectively final"
};
return 1;

default:
return 0;
}
}
}

0 comments on commit 60f1d4d

Please sign in to comment.