Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mpalat authored and rgrunber committed Jan 9, 2024
1 parent cebb31a commit 4f66b3d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
);
}
}

0 comments on commit 4f66b3d

Please sign in to comment.