diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java index 3e63121755b..94c715662f1 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java @@ -1266,7 +1266,7 @@ private void connectImplicitPermittedTypes(SourceTypeBinding sourceType) { // bug xxxx flag Error and return; } if (permSubTypes.size() == 0) { - if (!sourceType.isLocalType() && !sourceType.isRecord()) // error flagged already + if (!sourceType.isLocalType() && !sourceType.isRecord() && !sourceType.isEnum()) // error flagged already problemReporter().sealedSealedTypeMissingPermits(sourceType, this.referenceContext); return; } @@ -1278,7 +1278,7 @@ private void connectImplicitPermittedTypes(SourceTypeBinding sourceType) { void connectImplicitPermittedTypes() { TypeDeclaration typeDecl = this.referenceContext; SourceTypeBinding sourceType = typeDecl.binding; - if (sourceType.id == TypeIds.T_JavaLangObject || sourceType.isEnum()) // already handled + if (sourceType.id == TypeIds.T_JavaLangObject) // already handled return; if (sourceType.isSealed() && (typeDecl.permittedTypes == null || typeDecl.permittedTypes.length == 0)) { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java index f5f79488bd9..78e66a27fe9 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java @@ -9532,4 +9532,156 @@ void foo() { options ); } +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testIssue1641_003() { + if (!isJRE17Plus) + return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_17); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_17); + this.runNegativeTest( + new String[] { + "X.java", + """ + enum InterfaceInEnum { + INSTANCE; + sealed interface I { + final class C implements I {} + } + final class D implements I {} + final class E implements InterfaceInEnum.I {} + } + class X { + void foo() { + Zork(); + } + } + """}, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testIssue1641_004() { + if (!isJRE17Plus) + return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_17); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_17); + this.runNegativeTest( + new String[] { + "X.java", + """ + enum InterfaceInEnum { + INSTANCE; + sealed interface I { + final class C implements I {} + } + final class D implements I {} + } + class X { + void foo() { + Zork(); + } + } + """}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "unchecked", "rawtypes" }) +public void testIssue1641_005() { + if (!isJRE17Plus) + return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_17); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_17); + this.runNegativeTest( + new String[] { + "X.java", + """ + interface I { + enum E { + First {} + }; + } + class X { + void foo() { + Zork(); + } + } + """}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "unchecked", "rawtypes" }) +public void testIssue1641_006() { + if (!isJRE17Plus) + return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_17); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_17); + this.runNegativeTest( + new String[] { + "X.java", + """ + interface I { + enum E { + First { + @SuppressWarnings("unused") + enum F { + FirstOne { + interface J { + enum G { + FirstTwo {} + } + } + } + }; + } + }; + } + class X { + void foo() { + Zork(); + } + } + """}, + "----------\n" + + "1. ERROR in X.java (at line 19)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); +} }