From bb0e1b73902f66b7bab5143aef998736f4a9cbe1 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 31 Jul 2020 16:48:33 +0300 Subject: [PATCH] [FIR] Add diagnostic for constructor delegation cycles --- .../diagnostics/annotationClassMember.txt | 2 +- .../cyclicConstructorDelegationCall.kt | 67 +++++++++ .../cyclicConstructorDelegationCall.txt | 139 ++++++++++++++++++ .../fir/FirDiagnosticsTestGenerated.java | 5 + ...DiagnosticsWithLightTreeTestGenerated.java | 5 + .../declaration/DefaultDeclarationCheckers.kt | 1 + ...rCyclicConstructorDelegationCallChecker.kt | 66 +++++++++ .../fir/analysis/diagnostics/FirErrors.kt | 2 + .../converter/DeclarationsConverter.kt | 2 +- .../kotlin/fir/builder/RawFirBuilder.kt | 2 +- .../secondaryConstructorDelegateItself.fir.kt | 2 +- .../secondaryConstructorDelegateLoop.fir.kt | 6 +- .../enum/constructorInHeaderEnum.fir.kt | 2 +- .../tests/multiplatform/namedArguments.fir.kt | 2 +- .../constructorInObject.fir.kt | 20 --- .../constructorInObject.kt | 1 + .../cyclicDelegationCalls.fir.kt | 24 +-- .../secondaryConstructors/generics.fir.kt | 2 +- .../secondaryConstructors/generics2.fir.kt | 10 +- .../implicitSuperCallErrorsIfPrimary.fir.kt | 2 +- .../tests/secondaryConstructors/kt6992.fir.kt | 3 - .../tests/secondaryConstructors/kt6992.kt | 1 + .../tests/secondaryConstructors/kt6994.fir.kt | 2 +- .../redeclarations.fir.kt | 12 +- 24 files changed, 322 insertions(+), 58 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt create mode 100644 compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.txt create mode 100644 compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirCyclicConstructorDelegationCallChecker.kt delete mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.fir.kt diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/annotationClassMember.txt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/annotationClassMember.txt index ffdcb13fcba..c80f34bb11c 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/annotationClassMember.txt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/annotationClassMember.txt @@ -5,7 +5,7 @@ FILE: annotationClassMember.kt } public constructor(s: R|kotlin/Nothing?|): R|A| { - this() + super() } init { diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt new file mode 100644 index 00000000000..c5d6f2e7a4f --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt @@ -0,0 +1,67 @@ +class B +class C + +class A() { + constructor(a: Int) : this("test") {} + constructor(a: String) : this(10) {} + + constructor(a: Boolean) : this('\n') {} + constructor(a: Char) : this(0.0) {} + constructor(a: Double) : this(false) {} + + constructor(b: B) : this(3.14159265) {} + + constructor(c: C) : this() {} + constructor(a: List) : this(C()) {} +} + +class D { + constructor(i: Boolean) {} + constructor(i: Int) : this(3) {} +} + +class E { + // this is not an error about the + // selection of the proper constructor + // but a type mismatch for the first + // argument + constructor(e: T, i: Int) : this(i, 10) {} +} + +class I { + // this is not an error about the + // selection of the proper constructor + // but a type mismatch for the first + // argument + constructor(e: T, i: Int) : this(i, 10) +} + +class J { + constructor(e: T, i: Int) : this(i, 10) + constructor(e: Int, i: Int) +} + +class F(s: String) { + constructor(i: Boolean) {} + constructor(i: Int) : this(3) {} +} + +class G(x: Int) { + constructor() {} +} + +class H(x: Int) { + constructor() +} + +class K(x: Int) { + constructor() : this() {} +} + +class M { + constructor(m: Int) +} + +class U : M { + constructor() +} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.txt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.txt new file mode 100644 index 00000000000..9db508e926f --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.txt @@ -0,0 +1,139 @@ +FILE: cyclicConstructorDelegationCall.kt + public final class B : R|kotlin/Any| { + public constructor(): R|B| { + super() + } + + } + public final class C : R|kotlin/Any| { + public constructor(): R|C| { + super() + } + + } + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public constructor(a: R|kotlin/Int|): R|A| { + this(String(test)) + } + + public constructor(a: R|kotlin/String|): R|A| { + this(Int(10)) + } + + public constructor(a: R|kotlin/Boolean|): R|A| { + this(Char(10)) + } + + public constructor(a: R|kotlin/Char|): R|A| { + this(Double(0.0)) + } + + public constructor(a: R|kotlin/Double|): R|A| { + this(Boolean(false)) + } + + public constructor(b: R|B|): R|A| { + this(Double(3.14159265)) + } + + public constructor(c: R|C|): R|A| { + this() + } + + public constructor(a: R|kotlin/collections/List|): R|A| { + this(R|/C.C|()) + } + + } + public final class D : R|kotlin/Any| { + public constructor(i: R|kotlin/Boolean|): R|D| { + super() + } + + public constructor(i: R|kotlin/Int|): R|D| { + this(Int(3)) + } + + } + public final class E : R|kotlin/Any| { + public constructor(e: R|T|, i: R|kotlin/Int|): R|E| { + this|>(R|/i|, Int(10)) + } + + } + public final class I : R|kotlin/Any| { + public constructor(e: R|T|, i: R|kotlin/Int|): R|I| { + this|>(R|/i|, Int(10)) + } + + } + public final class J : R|kotlin/Any| { + public constructor(e: R|T|, i: R|kotlin/Int|): R|J| { + this|>(R|/i|, Int(10)) + } + + public constructor(e: R|kotlin/Int|, i: R|kotlin/Int|): R|J| { + super() + } + + } + public final class F : R|kotlin/Any| { + public constructor(s: R|kotlin/String|): R|F| { + super() + } + + public constructor(i: R|kotlin/Boolean|): R|F| { + super() + } + + public constructor(i: R|kotlin/Int|): R|F| { + this(Int(3)) + } + + } + public final class G : R|kotlin/Any| { + public constructor(x: R|kotlin/Int|): R|G| { + super() + } + + public constructor(): R|G| { + super() + } + + } + public final class H : R|kotlin/Any| { + public constructor(x: R|kotlin/Int|): R|H| { + super() + } + + public constructor(): R|H| { + super() + } + + } + public final class K : R|kotlin/Any| { + public constructor(x: R|kotlin/Int|): R|K| { + super() + } + + public constructor(): R|K| { + this() + } + + } + public final class M : R|kotlin/Any| { + public constructor(m: R|kotlin/Int|): R|M| { + super() + } + + } + public final class U : R|M| { + public constructor(): R|U| { + super() + } + + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 6c35950fdd9..03e65b19e72 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -916,6 +916,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/anonymousObjectByDelegate.kt"); } + @TestMetadata("cyclicConstructorDelegationCall.kt") + public void testCyclicConstructorDelegationCall() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt"); + } + @TestMetadata("incompatibleModifiers.kt") public void testIncompatibleModifiers() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/incompatibleModifiers.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 33fbd67867b..54655d015e0 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -916,6 +916,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/anonymousObjectByDelegate.kt"); } + @TestMetadata("cyclicConstructorDelegationCall.kt") + public void testCyclicConstructorDelegationCall() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt"); + } + @TestMetadata("incompatibleModifiers.kt") public void testIncompatibleModifiers() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/incompatibleModifiers.kt"); diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/DefaultDeclarationCheckers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/DefaultDeclarationCheckers.kt index 83403fc3a13..b550a6a9e2e 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/DefaultDeclarationCheckers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/DefaultDeclarationCheckers.kt @@ -20,6 +20,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() { override val memberDeclarationCheckers: List = listOf( FirInfixFunctionDeclarationChecker, FirExposedVisibilityDeclarationChecker, + FirCyclicConstructorDelegationCallChecker, ) override val constructorCheckers: List = listOf( diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirCyclicConstructorDelegationCallChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirCyclicConstructorDelegationCallChecker.kt new file mode 100644 index 00000000000..a8364061ff2 --- /dev/null +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirCyclicConstructorDelegationCallChecker.kt @@ -0,0 +1,66 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.analysis.checkers.declaration + +import org.jetbrains.kotlin.fir.FirSourceElement +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors +import org.jetbrains.kotlin.fir.declarations.FirConstructor +import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration +import org.jetbrains.kotlin.fir.declarations.FirRegularClass +import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference +import org.jetbrains.kotlin.utils.addToStdlib.safeAs + +object FirCyclicConstructorDelegationCallChecker : FirMemberDeclarationChecker() { + override fun check(declaration: FirMemberDeclaration, context: CheckerContext, reporter: DiagnosticReporter) { + if (declaration !is FirRegularClass) { + return + } + + val cyclicConstructors = mutableSetOf() + + for (it in declaration.declarations) { + if (it is FirConstructor && !it.isPrimary) { + it.findCycle(cyclicConstructors)?.let { visited -> + cyclicConstructors += visited + } + } + } + + cyclicConstructors.forEach { + reporter.reportCyclicConstructorDelegationCall(it.delegatedConstructor?.source) + } + } + + private fun FirConstructor.findCycle(knownCyclicConstructors: Set = emptySet()): Set? { + val visitedConstructors = mutableSetOf(this) + + var it = this + var delegated = this.getDelegated() + + while (!it.isPrimary && delegated != null) { + if (delegated in visitedConstructors || delegated in knownCyclicConstructors) { + return visitedConstructors + } + + it = delegated + delegated = delegated.getDelegated() + visitedConstructors.add(it) + } + + return null + } + + private fun FirConstructor.getDelegated(): FirConstructor? = delegatedConstructor + ?.calleeReference.safeAs() + ?.resolvedSymbol + ?.fir.safeAs() + + private fun DiagnosticReporter.reportCyclicConstructorDelegationCall(source: FirSourceElement?) { + source?.let { report(FirErrors.CYCLIC_CONSTRUCTOR_DELEGATION_CALL.on(it)) } + } +} \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index a602ab02c19..84821a5baed 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -64,6 +64,8 @@ object FirErrors { val VAR_ANNOTATION_PARAMETER by existing(Errors.VAR_ANNOTATION_PARAMETER) val NOT_AN_ANNOTATION_CLASS by error1() + val CYCLIC_CONSTRUCTOR_DELEGATION_CALL by warning0() + // Exposed visibility group val EXPOSED_TYPEALIAS_EXPANDED_TYPE by error3() val EXPOSED_FUNCTION_RETURN_TYPE by error3() diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index e6c2a49a989..d2077b092e7 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -834,7 +834,7 @@ class DeclarationsConverter( } val isImplicit = constructorDelegationCall.asText.isEmpty() - val isThis = (isImplicit && classWrapper.hasPrimaryConstructor) || thisKeywordPresent + val isThis = thisKeywordPresent //|| (isImplicit && classWrapper.hasPrimaryConstructor) val delegatedType = when { isThis -> classWrapper.delegatedSelfTypeRef diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index fe54fd30208..8d207320465 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -1095,7 +1095,7 @@ class RawFirBuilder( delegatedSelfTypeRef: FirTypeRef, hasPrimaryConstructor: Boolean, ): FirDelegatedConstructorCall { - val isThis = isCallToThis || (isImplicit && hasPrimaryConstructor) + val isThis = isCallToThis //|| (isImplicit && hasPrimaryConstructor) val source = this.toFirSourceElement() val delegatedType = when { isThis -> delegatedSelfTypeRef diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateItself.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateItself.fir.kt index 510b7e292f1..25aace182fd 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateItself.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateItself.fir.kt @@ -7,7 +7,7 @@ class Foo { bar = "" } - constructor(a: Int) : this(a) { + constructor(a: Int) : this(a) { bar = "a" } } diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateLoop.fir.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateLoop.fir.kt index 596b60c7c99..38b80bba8c4 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateLoop.fir.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unnecessaryLateinit/secondaryConstructorDelegateLoop.fir.kt @@ -7,12 +7,12 @@ class Foo { bar = "" } - constructor(a: Int) : this(a, 0, 0) { + constructor(a: Int) : this(a, 0, 0) { } - constructor(a: Int, b: Int) : this(a) { + constructor(a: Int, b: Int) : this(a) { } - constructor(a: Int, b: Int, c: Int) : this(a, b) { + constructor(a: Int, b: Int, c: Int) : this(a, b) { } } diff --git a/compiler/testData/diagnostics/tests/multiplatform/enum/constructorInHeaderEnum.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/enum/constructorInHeaderEnum.fir.kt index d06d0075a2d..71224ec2125 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/enum/constructorInHeaderEnum.fir.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/enum/constructorInHeaderEnum.fir.kt @@ -7,7 +7,7 @@ expect enum class En(x: Int) { E2(42), ; - constructor(s: String) + constructor(s: String) } expect enum class En2 { diff --git a/compiler/testData/diagnostics/tests/multiplatform/namedArguments.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/namedArguments.fir.kt index 5d35855ba45..49db2f1bf5c 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/namedArguments.fir.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/namedArguments.fir.kt @@ -4,7 +4,7 @@ // FILE: common.kt expect class Foo(zzz: Int) { - constructor(aaa: Boolean) + constructor(aaa: Boolean) fun f1(xxx: String): String } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt deleted file mode 100644 index db0e6e81180..00000000000 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -object A { - constructor() - init {} -} - -enum class B { - X() { - constructor() - } -} - -class C { - companion object { - constructor() - } -} - -val anonObject = object { - constructor() -} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.kt index ea4c7a76664..831a0f30b03 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/constructorInObject.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL object A { constructor() init {} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/cyclicDelegationCalls.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/cyclicDelegationCalls.fir.kt index e18880f5089..f775f2be4fe 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/cyclicDelegationCalls.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/cyclicDelegationCalls.fir.kt @@ -1,33 +1,33 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER class A1 { - constructor(): this() + constructor(): this() } class A2(x: Byte) { - constructor(x1: Int): this(x1, 1) - constructor(x1: Int, x2: Int): this(x1, x2, 2) - constructor(x1: Int, x2: Int, x3: Int): this(x1) + constructor(x1: Int): this(x1, 1) + constructor(x1: Int, x2: Int): this(x1, x2, 2) + constructor(x1: Int, x2: Int, x3: Int): this(x1) // delegating to previously declared cycle - constructor(x1: Double): this(1) + constructor(x1: Double): this(1) // delegating to cycle declared after - constructor(x1: String): this(1L) + constructor(x1: String): this(1L) - constructor(x1: Long): this(x1, 1L) - constructor(x1: Long, x2: Long): this(x1, x2, 2L) - constructor(x1: Long, x2: Long, x3: Long): this(x1) + constructor(x1: Long): this(x1, 1L) + constructor(x1: Long, x2: Long): this(x1, x2, 2L) + constructor(x1: Long, x2: Long, x3: Long): this(x1) // no cycle, just call to primary constuctor constructor(x1: Double, x2: Double): this(x1, x2, 1.0) constructor(x1: Double, x2: Double, x3: Double): this(x1, x2, x3, 1.0) constructor(x1: Double, x2: Double, x3: Double, x4: Double): this(1.toByte()) - constructor(): this("x", "y") + constructor(): this("x", "y") - constructor(x1: String, x2: String): this(x1, x2, "") - constructor(x1: String, x2: String, x3: String): this(x1, x2) + constructor(x1: String, x2: String): this(x1, x2, "") + constructor(x1: String, x2: String, x3: String): this(x1, x2) } open class B(x: Byte) diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/generics.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/generics.fir.kt index 8477ffe9249..7ca3ff8081d 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/generics.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/generics.fir.kt @@ -17,5 +17,5 @@ class A1 : B { } class A2 { - constructor(t: R, i: Int) : this(i, 1) + constructor(t: R, i: Int) : this(i, 1) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/generics2.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/generics2.fir.kt index d1e39c051a7..4d03f2ea5b5 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/generics2.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/generics2.fir.kt @@ -3,13 +3,13 @@ open class B(x: R1, y: R2) class A0 { - constructor(x: T1, y: T2): this(x, y) + constructor(x: T1, y: T2): this(x, y) - constructor(x: T1, y: T2, z: T2): this(x, 1) // ok, delegates to constructor(x: T1, y: Int) + constructor(x: T1, y: T2, z: T2): this(x, 1) // ok, delegates to constructor(x: T1, y: Int) - constructor(x: T1, y: Int): this(x, "") - constructor(x: T1): this(x, 1) - constructor(x: T1, y: T2, z: String): this(y, x) + constructor(x: T1, y: Int): this(x, "") + constructor(x: T1): this(x, 1) + constructor(x: T1, y: T2, z: String): this(y, x) } class A1 : B { diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/implicitSuperCallErrorsIfPrimary.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/implicitSuperCallErrorsIfPrimary.fir.kt index 479505b025f..0802ad93ff6 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/implicitSuperCallErrorsIfPrimary.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/implicitSuperCallErrorsIfPrimary.fir.kt @@ -2,6 +2,6 @@ open class A(p1: String) class B() : A("") { - constructor(s: String) { + constructor(s: String) { } } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.fir.kt deleted file mode 100644 index e97067195db..00000000000 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.fir.kt +++ /dev/null @@ -1,3 +0,0 @@ -class X(val t: T) { - constructor(t: String): this(t) -} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.kt index ea55fe28ebf..eae46ee168b 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6992.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class X(val t: T) { constructor(t: String): this(t) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/kt6994.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6994.fir.kt index f7e886bc963..af8b7419100 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/kt6994.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/kt6994.fir.kt @@ -1,4 +1,4 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER class X { - constructor(t: T, i: Int): this(i, 1) + constructor(t: T, i: Int): this(i, 1) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.fir.kt index b4275c2bd23..bedfc82ef2c 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/redeclarations.fir.kt @@ -1,9 +1,9 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER class A(x: String = "", y: String = "") { - constructor(x: String, y: String): this(x, y) - constructor(): this("", "") - constructor(): this("", "") + constructor(x: String, y: String): this(x, y) + constructor(): this("", "") + constructor(): this("", "") } class B { @@ -14,9 +14,9 @@ fun B(x: Int) {} class Outer { class A(x: String = "", y: String = "") { - constructor(x: String, y: String): this(x, y) - constructor(): this("", "") - constructor(): this("", "") + constructor(x: String, y: String): this(x, y) + constructor(): this("", "") + constructor(): this("", "") } class B {