diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/explicitDelegationCallRequired.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/explicitDelegationCallRequired.kt index 071f26b28ed..dc0a432c603 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/explicitDelegationCallRequired.kt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/explicitDelegationCallRequired.kt @@ -7,8 +7,8 @@ class B : A { constructor(z: String) : this() } -class C : A(20) { - constructor() +class C : A(20) { + constructor() constructor(z: String) : this() } diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/supertypeInitializedWithoutPrimaryConstructor.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/supertypeInitializedWithoutPrimaryConstructor.kt index 3d2860aba24..e846e991ad4 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/supertypeInitializedWithoutPrimaryConstructor.kt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/supertypeInitializedWithoutPrimaryConstructor.kt @@ -6,6 +6,6 @@ class D : C class E : C(10) class F() : C(10) -class G : C(10) { - constructor() : super(1) +class G : C(10) { + constructor() : super(1) } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirConflictsHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirConflictsHelpers.kt index 9bb087763b3..d428473572d 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirConflictsHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirConflictsHelpers.kt @@ -161,6 +161,19 @@ fun FirDeclarationCollector>.collectClassMembers(klass: FirReg } } + // Constructors of nested classes + // are collected when checking the outer + // class: this is because they may clash + // with functions from this outer class, + // so we should avoid checking them twice. + if (context.isTopLevel) { + scope.processDeclaredConstructors { + if (it.isCollectable() && it.isVisibleInClass(klass)) { + collect(it, FirRedeclarationPresenter.represent(it, klass), functionDeclarations) + } + } + } + val visitedProperties = mutableSetOf>() scope.collectLeafProperties().forEach { diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.fir.kt index 9168d52c96c..a94757abda7 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerSupertypeInitialization.fir.kt @@ -1,5 +1,5 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER open class B(x: Int) -class A : B(1) { - constructor(): super(1) +class A : B(1) { + constructor(): super(1) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.fir.kt deleted file mode 100644 index e9b668ea62f..00000000000 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.fir.kt +++ /dev/null @@ -1,27 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -class A(x: String = "", y: String = "") { - constructor(x: String, y: String): this(x, y) - constructor(): this("", "") - constructor(): this("", "") -} - -class B { - constructor(x: Int) -} - -fun B(x: Int) {} - -class Outer { - class A(x: String = "", y: String = "") { - constructor(x: String, y: String): this(x, y) - constructor(): this("", "") - constructor(): this("", "") - } - - class B { - constructor(x: Int) - } - - fun B(x: Int) {} -} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.kt index 9b3c8f4164c..94b9bd60004 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER class A(x: String = "", y: String = "") {