Skip to content

Commit 1e3e3a9

Browse files
[Enhanced Switch] ECG generated code hangs (#3398)
* Fixes #3395
1 parent 0c7adc8 commit 1e3e3a9

File tree

2 files changed

+43
-2
lines changed
  • org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast
  • org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression

2 files changed

+43
-2
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {
358358
}
359359
patternMatchLabel.place();
360360
} else {
361-
if (this.swich.containsNull)
362-
this.swich.nullProcessed |= true;
361+
if (this.swich.nullCase == this)
362+
this.swich.nullProcessed = true;
363363
}
364364
codeStream.recordPositionsFrom(pc, this.sourceStart);
365365
}

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9587,4 +9587,45 @@ public interface X {
95879587
"B1 -> B1, B1\n" +
95889588
"B2 -> B2, B2");
95899589
}
9590+
9591+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3395
9592+
// [Enhanced Switch] ECG generated code hangs
9593+
public void testIssue3395() {
9594+
runConformTest(
9595+
new String[] {
9596+
"X.java",
9597+
"""
9598+
public class X {
9599+
public static void main(String[] args) {
9600+
for (String s : new String [] { "World", "Check", "Hello", "Null", "Default" }) {
9601+
String sel = s.equals("Null") ? null : s;
9602+
switch (sel) {
9603+
case "World" -> System.out.print("World");
9604+
case String str when s.equals("Check") -> System.out.print("Check");
9605+
case "Hello" -> System.out.print("Hello");
9606+
case null -> System.out.print("Null");
9607+
default -> System.out.print("Default");
9608+
}
9609+
System.out.print("--");
9610+
}
9611+
System.out.println("");
9612+
for (String s : new String [] { "Default", "Null", "Hello", "Check", "World" }) {
9613+
String sel = s.equals("Null") ? null : s;
9614+
switch (sel) {
9615+
case "World" -> System.out.print("World");
9616+
case String str when s.equals("Check") -> System.out.print("Check");
9617+
case "Hello" -> System.out.print("Hello");
9618+
case null -> System.out.print("Null");
9619+
default -> System.out.print("Default");
9620+
}
9621+
System.out.print("--");
9622+
}
9623+
System.out.println("");
9624+
}
9625+
}
9626+
""",
9627+
},
9628+
"World--Check--Hello--Null--Default--\n" +
9629+
"Default--Null--Hello--Check--World--");
9630+
}
95909631
}

0 commit comments

Comments
 (0)