Prohibit super constructor call for 'expect' class
#KT-15490 Fixed
This commit is contained in:
@@ -564,6 +564,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtExpression> EXPECTED_PROPERTY_INITIALIZER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtPropertyDelegate> EXPECTED_DELEGATED_PROPERTY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> EXPECTED_LATEINIT_PROPERTY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtTypeAlias> ACTUAL_TYPE_ALIAS_NOT_TO_CLASS = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtTypeAlias>
|
||||
|
||||
+2
-1
@@ -272,6 +272,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(EXPECTED_PROPERTY_INITIALIZER, "Expected property cannot have an initializer");
|
||||
MAP.put(EXPECTED_DELEGATED_PROPERTY, "Expected property cannot be delegated");
|
||||
MAP.put(EXPECTED_LATEINIT_PROPERTY, "Expected property cannot be lateinit");
|
||||
MAP.put(SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS, "Expected classes cannot initialize supertypes");
|
||||
|
||||
MAP.put(ACTUAL_TYPE_ALIAS_NOT_TO_CLASS, "Right-hand side of actual type alias should be a class, not another type alias");
|
||||
MAP.put(ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE, "Aliased class should not have type parameters with declaration-site variance");
|
||||
@@ -555,8 +556,8 @@ public class DefaultErrorMessages {
|
||||
MAP.put(MANY_CLASSES_IN_SUPERTYPE_LIST, "Only one class may appear in a supertype list");
|
||||
MAP.put(SUPERTYPE_NOT_A_CLASS_OR_INTERFACE, "Only classes and interfaces may serve as supertypes");
|
||||
MAP.put(SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE, "Extension function type is not allowed as supertypes");
|
||||
MAP.put(SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE, "Suspend function type is not allowed as supertypes");
|
||||
MAP.put(SUPERTYPE_INITIALIZED_IN_INTERFACE, "Interfaces cannot initialize supertypes");
|
||||
MAP.put(SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE, "Suspend function type is not allowed as supertypes");
|
||||
MAP.put(CLASS_IN_SUPERTYPE_FOR_ENUM, "Enum class cannot inherit from classes");
|
||||
MAP.put(CONSTRUCTOR_IN_INTERFACE, "An interface may not have a constructor");
|
||||
MAP.put(METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE, "An interface may not implement a method of 'Any'");
|
||||
|
||||
@@ -316,6 +316,9 @@ public class BodyResolver {
|
||||
if (descriptor.getKind() == ClassKind.INTERFACE) {
|
||||
trace.report(SUPERTYPE_INITIALIZED_IN_INTERFACE.on(elementToMark));
|
||||
}
|
||||
if (descriptor.isExpect()) {
|
||||
trace.report(SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS.on(elementToMark));
|
||||
}
|
||||
KtTypeReference typeReference = call.getTypeReference();
|
||||
if (typeReference == null) return;
|
||||
if (primaryConstructor == null) {
|
||||
|
||||
+2
-2
@@ -4,12 +4,12 @@
|
||||
|
||||
expect enum class En<!EXPECTED_ENUM_CONSTRUCTOR!>(x: Int)<!> {
|
||||
E1,
|
||||
E2(42),
|
||||
E2<!SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS!>(42)<!>,
|
||||
;
|
||||
|
||||
<!EXPECTED_ENUM_CONSTRUCTOR!>constructor(s: String)<!>
|
||||
}
|
||||
|
||||
expect enum class En2 {
|
||||
E1<!NO_CONSTRUCTOR!>()<!>
|
||||
E1<!SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS, NO_CONSTRUCTOR!>()<!>
|
||||
}
|
||||
|
||||
@@ -8,10 +8,16 @@ interface J
|
||||
|
||||
expect class Foo : I, C, J
|
||||
|
||||
expect class Bar : C<!SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS, JS:SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS, JVM:SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS!>()<!>
|
||||
|
||||
// MODULE: m2-jvm(m1-common)
|
||||
// FILE: jvm.kt
|
||||
actual class Foo : I, C(), J
|
||||
|
||||
actual class <!ACTUAL_WITHOUT_EXPECT!>Bar<!>
|
||||
|
||||
// MODULE: m3-js(m1-common)
|
||||
// FILE: js.kt
|
||||
actual class Foo : I, J, C()
|
||||
|
||||
actual class Bar : C()
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
// -- Module: <m1-common> --
|
||||
package
|
||||
|
||||
public final expect class Bar : C {
|
||||
public constructor Bar()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class C {
|
||||
public constructor C()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
@@ -31,6 +38,13 @@ public interface J {
|
||||
// -- Module: <m2-jvm> --
|
||||
package
|
||||
|
||||
public final actual class Bar {
|
||||
public constructor Bar()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class C {
|
||||
public constructor C()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
@@ -61,6 +75,13 @@ public interface J {
|
||||
// -- Module: <m3-js> --
|
||||
package
|
||||
|
||||
public final actual class Bar : C {
|
||||
public constructor Bar()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class C {
|
||||
public constructor C()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
|
||||
Reference in New Issue
Block a user