Skip to content

Commit

Permalink
1641_enum_further_fixes (#1739)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpalat authored Dec 13, 2023
1 parent 2f4180a commit e1e7e10
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 2 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() && !sourceType.isRecord()) // error flagged already
if (!sourceType.isLocalType() && !sourceType.isRecord() && !sourceType.isEnum()) // 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()) // already handled
if (sourceType.id == TypeIds.T_JavaLangObject) // 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 @@ -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
);
}
}

0 comments on commit e1e7e10

Please sign in to comment.