Allow no super class initialization within header
if there is no primary constructor
This commit is contained in:
@@ -275,7 +275,11 @@ public class BodyResolver {
|
||||
// A "singleton in supertype" diagnostic will be reported later
|
||||
return;
|
||||
}
|
||||
if (descriptor.getKind() != ClassKind.TRAIT && !superClass.getConstructors().isEmpty() && !ErrorUtils.isError(superClass)) {
|
||||
if (descriptor.getKind() != ClassKind.TRAIT &&
|
||||
descriptor.getUnsubstitutedPrimaryConstructor() != null &&
|
||||
!superClass.getConstructors().isEmpty() &&
|
||||
!ErrorUtils.isError(superClass)
|
||||
) {
|
||||
trace.report(SUPERTYPE_NOT_INITIALIZED.on(specifier));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
open class B(open val parentProp: Int)
|
||||
val global: Int = 1
|
||||
class A : <!SUPERTYPE_NOT_INITIALIZED!>B<!> {
|
||||
class A : B {
|
||||
val myProp: Int = 1
|
||||
override val parentProp = 1
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
open class B(open val parentProperty: String)
|
||||
class A : <!SUPERTYPE_NOT_INITIALIZED!>B<!> {
|
||||
class A : B {
|
||||
val myProp: String = ""
|
||||
override val parentProperty: String = ""
|
||||
constructor(arg: String = <!UNRESOLVED_REFERENCE!>myProp<!>): super(<!UNRESOLVED_REFERENCE!>myProp<!>) {}
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
open class B
|
||||
trait C
|
||||
trait D
|
||||
class A : C, B, D {
|
||||
constructor() {}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package
|
||||
|
||||
internal final class A : C, B, D {
|
||||
public constructor A()
|
||||
public open override /*3*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*3*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*3*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
internal open class B {
|
||||
public constructor B()
|
||||
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
|
||||
}
|
||||
|
||||
internal trait C {
|
||||
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
|
||||
}
|
||||
|
||||
internal trait D {
|
||||
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
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ open class B(x: Double) {
|
||||
constructor(x: String): this(1.0) {}
|
||||
}
|
||||
trait C
|
||||
class A : <!SUPERTYPE_NOT_INITIALIZED!>B<!>, C {
|
||||
class A : B, C {
|
||||
constructor(): <!NONE_APPLICABLE!>super<!>(' ') { }
|
||||
constructor(x: Int) <!NONE_APPLICABLE!><!>{ }
|
||||
}
|
||||
|
||||
@@ -10427,6 +10427,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noSupertypeInitWithSecondaryConstructors.kt")
|
||||
public void testNoSupertypeInitWithSecondaryConstructors() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/noSupertypeInitWithSecondaryConstructors.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("superAnyNonEmpty.kt")
|
||||
public void testSuperAnyNonEmpty() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/superAnyNonEmpty.kt");
|
||||
|
||||
Reference in New Issue
Block a user