Skip to content

Commit

Permalink
- Correct live ranges computation
Browse files Browse the repository at this point in the history
- Add regression test for eclipse-jdt#1985
  • Loading branch information
srikanth-sankaran committed Feb 14, 2024
1 parent 63cdf2e commit 57f15cb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean
}
this.pattern.generateOptimizedBoolean(currentScope, codeStream, trueLabel, falseLabel);

for (LocalVariableBinding patternVariableBinding : this.pattern.bindingsWhenTrue()) {
codeStream.removeVariable(patternVariableBinding);
}
trueLabel.place();
codeStream.iconst_1();
codeStream.goto_(continueLabel);
falseLabel.place();
for (LocalVariableBinding patternVariableBinding : this.pattern.bindingsWhenTrue()) {
codeStream.removeVariable(patternVariableBinding);
}
codeStream.iconst_0();
continueLabel.place();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4340,4 +4340,51 @@ public static void main(String[] args) {
}
""" }, "res is true");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1985
// [Patterns][records] ECJ fails to generate code to deconstruct record in pattern
public void testIssue1985() {
runConformTest(new String[] { "X.java", """
public class X {
record R(int x) {
public int x() {
return 100 / this.x;
}
}
public static void main(String[] args) {
try {
boolean b = new R(0) instanceof R(int i);
} catch (Throwable t) {
System.out.println(t.getClass().getName());
}
}
}
""" },
"java.lang.MatchException");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1985
// [Patterns][records] ECJ fails to generate code to deconstruct record in pattern
public void testIssue1985_2() {
runConformTest(new String[] { "X.java", """
public class X {
boolean b = new R(0) instanceof R(int i);
record R(int x) {
public int x() {
return 100 / this.x;
}
}
public static void main(String[] args) {
try {
new X();
} catch (Throwable t) {
System.out.println(t.getClass().getName());
}
}
}
""" },
"java.lang.MatchException");
}
}

0 comments on commit 57f15cb

Please sign in to comment.