diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index b4b2e72f64c..a52fb3f0101 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -157,6 +157,7 @@ public interface Errors { DiagnosticFactory0 CYCLIC_CONSTRUCTOR_DELEGATION_CALL = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 SECONDARY_CONSTRUCTOR_IN_OBJECT = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR = DiagnosticFactory0.create(ERROR); // Trait-specific diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 9e30474f233..9d5850906c4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -415,6 +415,7 @@ public class DefaultErrorMessages { MAP.put(CYCLIC_CONSTRUCTOR_DELEGATION_CALL, "There's a cycle in the delegation calls chain"); MAP.put(SECONDARY_CONSTRUCTOR_IN_OBJECT, "Constructors are not allowed for objects"); + MAP.put(SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR, "Supertype initialization is impossible without primary constructor"); MAP.put(ILLEGAL_SELECTOR, "Expression ''{0}'' cannot be a selector (occur after a dot)", STRING); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java index debd47b93b9..eaf10300f0b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java @@ -305,7 +305,9 @@ public class BodyResolver { JetTypeReference typeReference = call.getTypeReference(); if (typeReference == null) return; if (primaryConstructor == null) { - assert descriptor.getKind() == ClassKind.TRAIT; + if (descriptor.getKind() != ClassKind.TRAIT) { + trace.report(SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR.on(call)); + } recordSupertype(typeReference, trace.getBindingContext().get(BindingContext.TYPE, typeReference)); return; } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.kt new file mode 100644 index 00000000000..faf1a4023ed --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.kt @@ -0,0 +1,5 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +open class B(x: Int) +class A : B(1) { + constructor(): super(1) {} +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.txt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.txt new file mode 100644 index 00000000000..3baef49265c --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.txt @@ -0,0 +1,15 @@ +package + +internal final class A : B { + public constructor A() + 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 open class B { + public constructor B(/*0*/ x: 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 + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index b9259500056..126edc8af46 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -10433,6 +10433,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("headerSupertypeInitialization.kt") + public void testHeaderSupertypeInitialization() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.kt"); + doTest(fileName); + } + @TestMetadata("memberAccessBeforeSuperCall.kt") public void testMemberAccessBeforeSuperCall() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/memberAccessBeforeSuperCall.kt");