Skip to content

Commit

Permalink
[Switch-Expression] Assertion failure while compiling enum class that…
Browse files Browse the repository at this point in the history
… uses switch expression with try block (eclipse-jdt#2317)

* Fixes eclipse-jdt#2233
  • Loading branch information
srikanth-sankaran authored Apr 11, 2024
1 parent 71d5fc0 commit 50880a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7737,6 +7737,15 @@ private TypeBinding retrieveLocalType(int currentPC, int resolvedPosition) {
int enumOffset = declaringClass.isEnum() ? 2 : 0; // String name, int ordinal
int argSlotSize = 1 + enumOffset; // this==aload0
if (this.methodDeclaration.binding.isConstructor()) {
if (declaringClass.isEnum()) {
switch (resolvedPosition) {
case 1:
return this.methodDeclaration.scope.getJavaLangString();
case 2:
return TypeBinding.INT;
default: break;
}
}
if (declaringClass.isNestedType()) {
ReferenceBinding[] enclosingTypes = declaringClass.syntheticEnclosingInstanceTypes();
if (enclosingTypes != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7098,5 +7098,36 @@ public static void main(String[] args) {
"Finally\n"
+ "Switch Expr = 10");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2233
// [Switch-Expression] Assertion failure while compiling enum class that uses switch expression with try block
public void testIssue2233() {
if (this.complianceLevel < ClassFileConstants.JDK16)
return;
this.runConformTest(
new String[] {
"X.java",
"""
public enum X {
PARAMETER, FIELD, METHOD;
X() {
System.out.println(switch (this) {
default -> {
try {
yield 10;
} finally {
}
}
});
}
public static void notmain(String [] args) {
X x = PARAMETER;
System.out.println(x);
}
}
"""
},
"");
}
}

0 comments on commit 50880a0

Please sign in to comment.