diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 4cca818234c..6f0684cd419 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -165,7 +165,7 @@ public interface Errors { DiagnosticFactory0 CYCLIC_CONSTRUCTOR_DELEGATION_CALL = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 SECONDARY_CONSTRUCTOR_IN_OBJECT = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 CONSTRUCTOR_IN_OBJECT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory0 SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED = @@ -188,7 +188,7 @@ public interface Errors { .create(WARNING, modifierSetPosition(JetTokens.OPEN_KEYWORD)); DiagnosticFactory0 TRAIT_CAN_NOT_BE_FINAL = DiagnosticFactory0.create(ERROR, FINAL_MODIFIER); - DiagnosticFactory0 CONSTRUCTOR_IN_TRAIT = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 CONSTRUCTOR_IN_TRAIT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory0 SUPERTYPE_INITIALIZED_IN_TRAIT = DiagnosticFactory0.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt index ce2fcc10b25..9380a554768 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt @@ -156,6 +156,11 @@ public object PositioningStrategies { is JetObjectDeclaration -> { return DECLARATION_NAME.mark(element) } + is JetPrimaryConstructor -> { + val begin = element.getConstructorKeyword() ?: element.getValueParameterList() ?: return markElement(element) + val end = element.getValueParameterList() ?: element.getConstructorKeyword() + return markRange(begin, end) + } is JetSecondaryConstructor -> { return markRange(element.getConstructorKeyword(), element.getValueParameterList() ?: element.getConstructorKeyword()) } 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 2dee914eebe..6ac0828d1ce 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -403,7 +403,7 @@ public class DefaultErrorMessages { MAP.put(SINGLETON_IN_SUPERTYPE, "Cannot inherit from a singleton"); 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(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(PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED, "Primary constructor call expected"); MAP.put(DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR, "Call to super is not allowed in enum constructor"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java index 832d2f67870..e689183576f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.java @@ -303,9 +303,9 @@ public class DeclarationsChecker { } private void checkConstructorInTrait(JetClass klass) { - JetParameterList primaryConstructorParameterList = klass.getPrimaryConstructorParameterList(); - if (primaryConstructorParameterList != null) { - trace.report(CONSTRUCTOR_IN_TRAIT.on(primaryConstructorParameterList)); + JetPrimaryConstructor primaryConstructor = klass.getPrimaryConstructor(); + if (primaryConstructor != null) { + trace.report(CONSTRUCTOR_IN_TRAIT.on(primaryConstructor)); } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LazyTopDownAnalyzer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LazyTopDownAnalyzer.kt index 08a963f20c0..8d45630aa04 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LazyTopDownAnalyzer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LazyTopDownAnalyzer.kt @@ -23,7 +23,7 @@ import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.diagnostics.Errors.CONSTRUCTOR_IN_TRAIT import org.jetbrains.kotlin.diagnostics.Errors.MANY_COMPANION_OBJECTS -import org.jetbrains.kotlin.diagnostics.Errors.SECONDARY_CONSTRUCTOR_IN_OBJECT +import org.jetbrains.kotlin.diagnostics.Errors.CONSTRUCTOR_IN_OBJECT import org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.* @@ -176,7 +176,7 @@ public class LazyTopDownAnalyzer { } else if (jetDeclaration is JetSecondaryConstructor) { if (DescriptorUtils.isSingletonOrAnonymousObject(classDescriptor)) { - trace!!.report(SECONDARY_CONSTRUCTOR_IN_OBJECT.on(jetDeclaration)) + trace!!.report(CONSTRUCTOR_IN_OBJECT.on(jetDeclaration)) } else if (classDescriptor.getKind() == ClassKind.INTERFACE) { trace!!.report(CONSTRUCTOR_IN_TRAIT.on(jetDeclaration)) diff --git a/compiler/testData/diagnostics/tests/TraitWithConstructor.kt b/compiler/testData/diagnostics/tests/TraitWithConstructor.kt index 92374c88b6a..5d8be591152 100644 --- a/compiler/testData/diagnostics/tests/TraitWithConstructor.kt +++ b/compiler/testData/diagnostics/tests/TraitWithConstructor.kt @@ -4,10 +4,13 @@ interface T1(val x: String) {} interface T2() {} -interface T3(a: Int) {} +interface T3 private constructor(a: Int) {} interface T4 { - constructor(a: Int) { + constructor(a: Int) { val b: Int = 1 - } -} \ No newline at end of file + } +} + +interface T5 private () : T4 {} +interface T6 private : T5 {} diff --git a/compiler/testData/diagnostics/tests/TraitWithConstructor.txt b/compiler/testData/diagnostics/tests/TraitWithConstructor.txt index 8acdbf59e4b..22c5b532d11 100644 --- a/compiler/testData/diagnostics/tests/TraitWithConstructor.txt +++ b/compiler/testData/diagnostics/tests/TraitWithConstructor.txt @@ -23,7 +23,7 @@ internal interface T2 { } internal interface T3 { - public constructor T3(/*0*/ a: kotlin.Int) + private constructor T3(/*0*/ a: 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 @@ -34,3 +34,15 @@ internal interface T4 { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } + +internal interface T5 : T4 { + 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 interface T6 : T5 { + 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/testData/diagnostics/tests/secondaryConstructors/constructorInObject.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.kt index 8d739749120..ea4c7a76664 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.kt @@ -1,20 +1,20 @@ object A { - constructor() - init {} + constructor() + init {} } enum class B { X() { - constructor() - } + constructor() + } } class C { companion object { - constructor() - } + constructor() + } } val anonObject = object { - constructor() -} + constructor() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.kt index aa6be73d7e4..c065db8636a 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInTrait.kt @@ -1,3 +1,3 @@ interface A { - constructor() -} \ No newline at end of file + constructor() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt index 82912ad0563..a1bb8e04691 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/platformStatic/constructors.kt @@ -6,4 +6,4 @@ class A { } } -class C platformStatic constructor() +class C platformStatic constructor()