KT-2697 Prohibit enum inheritance
#KT-2697 Fixed
This commit is contained in:
@@ -253,6 +253,7 @@ public interface Errors {
|
|||||||
SimpleDiagnosticFactory<JetTypeReference> MANY_CLASSES_IN_SUPERTYPE_LIST = SimpleDiagnosticFactory.create(ERROR);
|
SimpleDiagnosticFactory<JetTypeReference> MANY_CLASSES_IN_SUPERTYPE_LIST = SimpleDiagnosticFactory.create(ERROR);
|
||||||
SimpleDiagnosticFactory<JetTypeReference> SUPERTYPE_NOT_A_CLASS_OR_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
SimpleDiagnosticFactory<JetTypeReference> SUPERTYPE_NOT_A_CLASS_OR_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
SimpleDiagnosticFactory<PsiElement> SUPERTYPE_INITIALIZED_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
SimpleDiagnosticFactory<PsiElement> SUPERTYPE_INITIALIZED_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
SimpleDiagnosticFactory<PsiElement> CLASS_IN_SUPERTYPE_FOR_ENUM = SimpleDiagnosticFactory.create(ERROR);
|
||||||
SimpleDiagnosticFactory<PsiElement> CONSTRUCTOR_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
SimpleDiagnosticFactory<PsiElement> CONSTRUCTOR_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR);
|
||||||
SimpleDiagnosticFactory<JetTypeReference> SUPERTYPE_APPEARS_TWICE = SimpleDiagnosticFactory.create(ERROR);
|
SimpleDiagnosticFactory<JetTypeReference> SUPERTYPE_APPEARS_TWICE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
SimpleDiagnosticFactory<JetTypeReference> FINAL_SUPERTYPE = SimpleDiagnosticFactory.create(ERROR);
|
SimpleDiagnosticFactory<JetTypeReference> FINAL_SUPERTYPE = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|||||||
+1
@@ -281,6 +281,7 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(MANY_CLASSES_IN_SUPERTYPE_LIST, "Only one class may appear in a supertype list");
|
MAP.put(MANY_CLASSES_IN_SUPERTYPE_LIST, "Only one class may appear in a supertype list");
|
||||||
MAP.put(SUPERTYPE_NOT_A_CLASS_OR_TRAIT, "Only classes and traits may serve as supertypes");
|
MAP.put(SUPERTYPE_NOT_A_CLASS_OR_TRAIT, "Only classes and traits may serve as supertypes");
|
||||||
MAP.put(SUPERTYPE_INITIALIZED_IN_TRAIT, "Traits cannot initialize supertypes");
|
MAP.put(SUPERTYPE_INITIALIZED_IN_TRAIT, "Traits cannot initialize supertypes");
|
||||||
|
MAP.put(CLASS_IN_SUPERTYPE_FOR_ENUM, "Enum class cannot inherit from classes");
|
||||||
MAP.put(CONSTRUCTOR_IN_TRAIT, "A trait may not have a constructor");
|
MAP.put(CONSTRUCTOR_IN_TRAIT, "A trait may not have a constructor");
|
||||||
MAP.put(SUPERTYPE_APPEARS_TWICE, "A supertype appears twice");
|
MAP.put(SUPERTYPE_APPEARS_TWICE, "A supertype appears twice");
|
||||||
MAP.put(FINAL_SUPERTYPE, "This type is final, so it cannot be inherited from");
|
MAP.put(FINAL_SUPERTYPE, "This type is final, so it cannot be inherited from");
|
||||||
|
|||||||
@@ -287,6 +287,9 @@ public class BodyResolver {
|
|||||||
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
|
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
|
||||||
if (classDescriptor != null) {
|
if (classDescriptor != null) {
|
||||||
if (classDescriptor.getKind() != ClassKind.TRAIT) {
|
if (classDescriptor.getKind() != ClassKind.TRAIT) {
|
||||||
|
if (supertypeOwner.getKind() == ClassKind.ENUM_CLASS) {
|
||||||
|
trace.report(CLASS_IN_SUPERTYPE_FOR_ENUM.on(typeReference));
|
||||||
|
}
|
||||||
if (classAppeared) {
|
if (classAppeared) {
|
||||||
trace.report(MANY_CLASSES_IN_SUPERTYPE_LIST.on(typeReference));
|
trace.report(MANY_CLASSES_IN_SUPERTYPE_LIST.on(typeReference));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// FILE: test.kt
|
||||||
|
enum class MyEnum(): <!CLASS_IN_SUPERTYPE_FOR_ENUM!>MyClass<!>() {}
|
||||||
|
enum class MyEnum2(): MyTrait {}
|
||||||
|
enum class MyEnum3(): <!INVISIBLE_MEMBER, CLASS_IN_SUPERTYPE_FOR_ENUM, FINAL_SUPERTYPE!>MyEnumBase<!>() {}
|
||||||
|
|
||||||
|
open class MyClass() {}
|
||||||
|
|
||||||
|
enum class MyEnumBase() {}
|
||||||
|
|
||||||
|
trait MyTrait {}
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user