Skip to content

Commit

Permalink
[Enhanced Switch] ECG generated code hangs (#3398)
Browse files Browse the repository at this point in the history
* Fixes #3395
  • Loading branch information
srikanth-sankaran authored Dec 4, 2024
1 parent 0c7adc8 commit 1e3e3a9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {
}
patternMatchLabel.place();
} else {
if (this.swich.containsNull)
this.swich.nullProcessed |= true;
if (this.swich.nullCase == this)
this.swich.nullProcessed = true;
}
codeStream.recordPositionsFrom(pc, this.sourceStart);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9587,4 +9587,45 @@ public interface X {
"B1 -> B1, B1\n" +
"B2 -> B2, B2");
}

// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3395
// [Enhanced Switch] ECG generated code hangs
public void testIssue3395() {
runConformTest(
new String[] {
"X.java",
"""
public class X {
public static void main(String[] args) {
for (String s : new String [] { "World", "Check", "Hello", "Null", "Default" }) {
String sel = s.equals("Null") ? null : s;
switch (sel) {
case "World" -> System.out.print("World");
case String str when s.equals("Check") -> System.out.print("Check");
case "Hello" -> System.out.print("Hello");
case null -> System.out.print("Null");
default -> System.out.print("Default");
}
System.out.print("--");
}
System.out.println("");
for (String s : new String [] { "Default", "Null", "Hello", "Check", "World" }) {
String sel = s.equals("Null") ? null : s;
switch (sel) {
case "World" -> System.out.print("World");
case String str when s.equals("Check") -> System.out.print("Check");
case "Hello" -> System.out.print("Hello");
case null -> System.out.print("Null");
default -> System.out.print("Default");
}
System.out.print("--");
}
System.out.println("");
}
}
""",
},
"World--Check--Hello--Null--Default--\n" +
"Default--Null--Hello--Check--World--");
}
}

0 comments on commit 1e3e3a9

Please sign in to comment.