Enum with interface keywords leads to fail in DeclarationChecker
This commit is contained in:
@@ -635,10 +635,6 @@ public class DeclarationsChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkEnumEntry(@NotNull JetEnumEntry enumEntry, @NotNull ClassDescriptor classDescriptor) {
|
private void checkEnumEntry(@NotNull JetEnumEntry enumEntry, @NotNull ClassDescriptor classDescriptor) {
|
||||||
DeclarationDescriptor declaration = classDescriptor.getContainingDeclaration();
|
|
||||||
assert DescriptorUtils.isEnumClass(declaration) : "Enum entry should be declared in enum class: " + classDescriptor;
|
|
||||||
ClassDescriptor enumClass = (ClassDescriptor) declaration;
|
|
||||||
|
|
||||||
if (enumEntryUsesDeprecatedSuperConstructor(enumEntry)) {
|
if (enumEntryUsesDeprecatedSuperConstructor(enumEntry)) {
|
||||||
trace.report(Errors.ENUM_ENTRY_USES_DEPRECATED_SUPER_CONSTRUCTOR.on(enumEntry, classDescriptor));
|
trace.report(Errors.ENUM_ENTRY_USES_DEPRECATED_SUPER_CONSTRUCTOR.on(enumEntry, classDescriptor));
|
||||||
}
|
}
|
||||||
@@ -650,23 +646,34 @@ public class DeclarationsChecker {
|
|||||||
trace.report(Errors.ENUM_ENTRY_AFTER_ENUM_MEMBER.on(enumEntry, classDescriptor));
|
trace.report(Errors.ENUM_ENTRY_AFTER_ENUM_MEMBER.on(enumEntry, classDescriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<JetDelegationSpecifier> delegationSpecifiers = enumEntry.getDelegationSpecifiers();
|
DeclarationDescriptor declaration = classDescriptor.getContainingDeclaration();
|
||||||
ConstructorDescriptor constructor = enumClass.getUnsubstitutedPrimaryConstructor();
|
if (DescriptorUtils.isEnumClass(declaration)) {
|
||||||
if ((constructor == null || !constructor.getValueParameters().isEmpty()) && delegationSpecifiers.isEmpty()) {
|
ClassDescriptor enumClass = (ClassDescriptor) declaration;
|
||||||
trace.report(ENUM_ENTRY_SHOULD_BE_INITIALIZED.on(enumEntry, enumClass));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
|
List<JetDelegationSpecifier> delegationSpecifiers = enumEntry.getDelegationSpecifiers();
|
||||||
JetTypeReference typeReference = delegationSpecifier.getTypeReference();
|
ConstructorDescriptor constructor = enumClass.getUnsubstitutedPrimaryConstructor();
|
||||||
if (typeReference != null) {
|
if ((constructor == null || !constructor.getValueParameters().isEmpty()) && delegationSpecifiers.isEmpty()) {
|
||||||
JetType type = trace.getBindingContext().get(TYPE, typeReference);
|
trace.report(ENUM_ENTRY_SHOULD_BE_INITIALIZED.on(enumEntry, enumClass));
|
||||||
if (type != null) {
|
}
|
||||||
JetType enumType = enumClass.getDefaultType();
|
|
||||||
if (!type.getConstructor().equals(enumType.getConstructor())) {
|
for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
|
||||||
trace.report(ENUM_ENTRY_ILLEGAL_TYPE.on(typeReference, enumClass));
|
JetTypeReference typeReference = delegationSpecifier.getTypeReference();
|
||||||
|
if (typeReference != null) {
|
||||||
|
JetType type = trace.getBindingContext().get(TYPE, typeReference);
|
||||||
|
if (type != null) {
|
||||||
|
JetType enumType = enumClass.getDefaultType();
|
||||||
|
if (!type.getConstructor().equals(enumType.getConstructor())) {
|
||||||
|
trace.report(ENUM_ENTRY_ILLEGAL_TYPE.on(typeReference, enumClass));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
assert DescriptorUtils.isTrait(declaration) : "Enum entry should be declared in enum class: " +
|
||||||
|
classDescriptor + " " +
|
||||||
|
classDescriptor.getKind();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<!ILLEGAL_ENUM_ANNOTATION!>enum<!> interface Some {
|
||||||
|
// Enum part
|
||||||
|
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED, ENUM_ENTRY_USES_DEPRECATED_OR_NO_DELIMITER!>D<!>
|
||||||
|
|
||||||
|
// Interface like part
|
||||||
|
fun test()
|
||||||
|
val foo: Int
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal interface Some {
|
||||||
|
public enum entry D : Some {
|
||||||
|
private constructor D()
|
||||||
|
internal abstract override /*1*/ /*fake_override*/ val foo: kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
internal abstract override /*1*/ /*fake_override*/ fun test(): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
internal abstract val foo: kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
internal abstract fun test(): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
data annotation enum class E {
|
data annotation enum class E {
|
||||||
D
|
D
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum annotation E1 {
|
||||||
|
D
|
||||||
|
}
|
||||||
@@ -33,3 +33,31 @@ JetFile: EnumWithAnnotationKeyword.kt
|
|||||||
PsiElement(IDENTIFIER)('D')
|
PsiElement(IDENTIFIER)('D')
|
||||||
PsiWhiteSpace('\n')
|
PsiWhiteSpace('\n')
|
||||||
PsiElement(RBRACE)('}')
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n\n')
|
||||||
|
FUN
|
||||||
|
MODIFIER_LIST
|
||||||
|
PsiElement(enum)('enum')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
ANNOTATION_ENTRY
|
||||||
|
CONSTRUCTOR_CALLEE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('annotation')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
ANNOTATION_ENTRY
|
||||||
|
CONSTRUCTOR_CALLEE
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('E1')
|
||||||
|
PsiErrorElement:Expecting a top level declaration
|
||||||
|
<empty list>
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
BLOCK
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('D')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
@@ -5,3 +5,7 @@ enum interface class E1 {
|
|||||||
interface enum class E2 {
|
interface enum class E2 {
|
||||||
D
|
D
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum interface E3 {
|
||||||
|
D
|
||||||
|
}
|
||||||
@@ -55,3 +55,20 @@ JetFile: InterfaceWithEnumKeyword.kt
|
|||||||
<empty list>
|
<empty list>
|
||||||
PsiWhiteSpace('\n')
|
PsiWhiteSpace('\n')
|
||||||
PsiElement(RBRACE)('}')
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n\n')
|
||||||
|
CLASS
|
||||||
|
MODIFIER_LIST
|
||||||
|
PsiElement(enum)('enum')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(interface)('interface')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('E3')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
CLASS_BODY
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
ENUM_ENTRY
|
||||||
|
OBJECT_DECLARATION_NAME
|
||||||
|
PsiElement(IDENTIFIER)('D')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
@@ -5193,6 +5193,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("interfaceWithEnumKeyword.kt")
|
||||||
|
public void testInterfaceWithEnumKeyword() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/enum/interfaceWithEnumKeyword.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("isEnumEntry.kt")
|
@TestMetadata("isEnumEntry.kt")
|
||||||
public void testIsEnumEntry() throws Exception {
|
public void testIsEnumEntry() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/enum/isEnumEntry.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/enum/isEnumEntry.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user