Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhanced Switch] ECJ generated code hangs #3398

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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--");
}
}
Loading