From 7963ba1233d62cdbaa552a4247047ca65e389ea8 Mon Sep 17 00:00:00 2001 From: Manoj N Palat Date: Fri, 8 Dec 2023 19:55:45 +0530 Subject: [PATCH] Fixes #1641 (#1713) --- .../internal/compiler/lookup/ClassScope.java | 4 +- .../RecordsRestrictedClassTest.java | 78 ++++++++++++++++++- 2 files changed, 79 insertions(+), 3 deletions(-) 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 04eb5c817de..3e63121755b 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()) // error flagged already + if (!sourceType.isLocalType() && !sourceType.isRecord()) // 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() || sourceType.isRecord()) // already handled + if (sourceType.id == TypeIds.T_JavaLangObject || sourceType.isEnum()) // 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 ad68f420862..f5f79488bd9 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 @@ -30,7 +30,7 @@ public class RecordsRestrictedClassTest extends AbstractRegressionTest { static { // TESTS_NUMBERS = new int [] { 40 }; // TESTS_RANGE = new int[] { 1, -1 }; -// TESTS_NAMES = new String[] { "testIssue1218_001"}; +// TESTS_NAMES = new String[] { "testIssue1641"}; } public static Class testClass() { @@ -9456,4 +9456,80 @@ public void testIssue1218_001() { "Syntax error, insert \"RecordBody\" to complete ClassBodyDeclarations\n" + "----------\n"); } +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testIssue1641_001() { + 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", + """ + record InterfaceInRecord() { + sealed interface I { + enum Empty implements I { + INSTANCE; + } + record Single(double value) implements I { + } + } + } + class X { + void foo() { + Zork(); + } + } + + """}, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testIssue1641_002() { + 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", + """ + record InterfaceInRecord() { + sealed interface I { + final class C implements I { + } + } + } + class X { + void foo() { + Zork(); + } + } + + """}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); +} }