Skip to content

Commit bad101c

Browse files
ECJ reports about non-existing modifiers on a local class in a switch expression (#4614)
* Fixes #4584
1 parent 6fed42f commit bad101c

File tree

2 files changed

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

2 files changed

+28
-2
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ private void checkAndSetModifiers() {
596596
}
597597
}
598598
}
599-
} else if (this.parent.referenceContext() instanceof TypeDeclaration) {
600-
TypeDeclaration typeDecl = (TypeDeclaration) this.parent.referenceContext();
599+
} else if (this.parent instanceof ClassScope classScope && classScope.referenceContext != null) {
600+
TypeDeclaration typeDecl = classScope.referenceContext;
601601
if (TypeDeclaration.kind(typeDecl.modifiers) == TypeDeclaration.INTERFACE_DECL) {
602602
// Sec 8.1.3 applies for local types as well
603603
modifiers |= ClassFileConstants.AccStatic;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,4 +1705,30 @@ public void testBug574791_3() {
17051705
"Hi from MyTest\n" +
17061706
"Hi from EnumTester");
17071707
}
1708+
// ECJ reports about non-existing modifiers on a local class in a switch expression
1709+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4584
1710+
public void testIssue4584() throws Exception {
1711+
runConformTest(
1712+
new String[] {
1713+
"X.java",
1714+
"""
1715+
public interface X {
1716+
int i = switch (0) {
1717+
case 2 -> {
1718+
class ParentLocal { // This is rejected
1719+
}
1720+
yield 1;
1721+
}
1722+
default -> {
1723+
yield 0;
1724+
}
1725+
};
1726+
public static void main(String [] args) {
1727+
System.out.println("OK!");
1728+
}
1729+
}
1730+
"""
1731+
},
1732+
"OK!");
1733+
}
17081734
}

0 commit comments

Comments
 (0)