From ceaffb1e8b2e23dedfc327be2f36f8da79b7c57e Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 27 Jul 2020 13:17:50 +0300 Subject: [PATCH] [FIR] Don't report duplicated errors in implicit primary constructors --- .../problems/KJKComplexHierarchyNestedLoop.kt | 2 +- .../ErrorNodeDiagnosticCollectorComponent.kt | 13 +++++++-- .../withCompanion/noMembers_after.fir.kt | 2 +- .../withCompanion/noMembers_before.fir.kt | 2 +- .../finalUpperBoundWithoutOverride.fir.kt | 6 ++-- .../typeReferenceError.fir.kt | 2 +- .../kt21515/inheritedFromDeprecatedNew.fir.kt | 28 +++++++++---------- .../kt21515/inheritedFromDeprecatedOld.fir.kt | 28 +++++++++---------- .../objects/kt21515/staticsFromJavaNew.fir.kt | 2 +- .../objects/kt21515/staticsFromJavaOld.fir.kt | 2 +- .../tests/regressions/kt9620.fir.kt | 2 +- .../diagnostics/tests/scopes/kt1080.fir.kt | 2 +- 12 files changed, 49 insertions(+), 42 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/KJKComplexHierarchyNestedLoop.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/KJKComplexHierarchyNestedLoop.kt index 4b1603dfc7b..4abc5169434 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/KJKComplexHierarchyNestedLoop.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/KJKComplexHierarchyNestedLoop.kt @@ -1,6 +1,6 @@ // FILE: K1.kt class K2: J1() { - class Q : Nested() + class Q : Nested() fun bar() { foo() baz() diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt index 105e6f7e0dc..0267a1b9308 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollector import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticFactory0 import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors +import org.jetbrains.kotlin.fir.declarations.FirConstructor import org.jetbrains.kotlin.fir.declarations.FirErrorFunction import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor import org.jetbrains.kotlin.fir.diagnostics.* @@ -31,9 +32,15 @@ class ErrorNodeDiagnosticCollectorComponent(collector: AbstractDiagnosticCollect } override fun visitErrorTypeRef(errorTypeRef: FirErrorTypeRef, data: CheckerContext) { - if (data.containingDeclarations.lastOrNull() is FirDefaultPropertyAccessor) { - // It always uses the same type ref as the corresponding property - return + when (val lastContainingDeclaration = data.containingDeclarations.lastOrNull()) { + is FirDefaultPropertyAccessor -> { + // It always uses the same type ref as the corresponding property + return + } + is FirConstructor -> if (lastContainingDeclaration.source?.kind is FirFakeSourceElementKind) { + // Implicit primary constructor uses the same type ref as the corresponding property + return + } } val source = errorTypeRef.source ?: return runCheck { reportFirDiagnostic(errorTypeRef.diagnostic, source, it) } diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_after.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_after.fir.kt index 9eaf38b7ce6..03edfed7869 100644 --- a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_after.fir.kt +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_after.fir.kt @@ -9,7 +9,7 @@ public class C { open class Base () - class Foo : Data() + class Foo : Data() companion object : DerivedAbstract() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_before.fir.kt b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_before.fir.kt index 0702677a7b5..db2fa209e9b 100644 --- a/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_before.fir.kt +++ b/compiler/testData/diagnostics/tests/cyclicHierarchy/withCompanion/noMembers_before.fir.kt @@ -9,7 +9,7 @@ public class C { open class Base () - class Foo : Data() + class Foo : Data() companion object : DerivedAbstract() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt b/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt index a6da0745c19..46fcf0deda7 100644 --- a/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt +++ b/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt @@ -51,11 +51,11 @@ interface MessageManager9 : Manager { fun execute4() {} } -object MessageManager10 : Message5() { +object MessageManager10 : Message5() { fun execute() {} } -class MessageManager11 : Message5>() { +class MessageManager11 : Message5>() { fun Message5> execute() {} } @@ -63,7 +63,7 @@ data class MessageManager12(val x: Int) : execute() {} } -sealed class MessageManager13 : Message5() { +sealed class MessageManager13 : Message5() { fun execute() {} } diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.fir.kt index 9892136cb06..23e0aa59a77 100644 --- a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.fir.kt +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.fir.kt @@ -1,3 +1,3 @@ package typeReferenceError -class Pair<:(val c: fun main() \ No newline at end of file +class Pair<:(val c: fun main() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedNew.fir.kt index 35e04b77e2d..dec2e99258d 100644 --- a/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedNew.fir.kt +++ b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedNew.fir.kt @@ -73,28 +73,28 @@ open class C : O.B() { open class n : FromCompanionC() // INVISIBLE: direct superclasses themselves. - open class a : A() - open class b : B() + open class a : A() + open class b : B() // DEPRECATED: Classifiers from companions of direct superclasses - open class e : FromCompanionA() - open class f : FromCompanionB() + open class e : FromCompanionA() + open class f : FromCompanionB() // INVISIBLE: "cousin" supertypes themselves - open class g : Alpha() - open class h : Beta() - open class i : Gamma() + open class g : Alpha() + open class h : Beta() + open class i : Gamma() // DEPRECATED: classifiers from "cousin" superclasses - open class k : FromAlpha() - open class l : FromBeta() - open class m : FromGamma() + open class k : FromAlpha() + open class l : FromBeta() + open class m : FromGamma() // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses - open class o : FromCompanionAlpha() - open class p : FromCompanionBeta() - open class q : FromCompanionGamma() + open class o : FromCompanionAlpha() + open class p : FromCompanionBeta() + open class q : FromCompanionGamma() // DEPRECATED: Classifiers from supertypes of our own companion - open class r : FromDelta() + open class r : FromDelta() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedOld.fir.kt index 52532436fbc..8a697de1e51 100644 --- a/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedOld.fir.kt +++ b/compiler/testData/diagnostics/tests/objects/kt21515/inheritedFromDeprecatedOld.fir.kt @@ -73,28 +73,28 @@ open class C : O.B() { open class n : FromCompanionC() // INVISIBLE: direct superclasses themselves. - open class a : A() - open class b : B() + open class a : A() + open class b : B() // DEPRECATED: Classifiers from companions of direct superclasses - open class e : FromCompanionA() - open class f : FromCompanionB() + open class e : FromCompanionA() + open class f : FromCompanionB() // INVISIBLE: "cousin" supertypes themselves - open class g : Alpha() - open class h : Beta() - open class i : Gamma() + open class g : Alpha() + open class h : Beta() + open class i : Gamma() // DEPRECATED: classifiers from "cousin" superclasses - open class k : FromAlpha() - open class l : FromBeta() - open class m : FromGamma() + open class k : FromAlpha() + open class l : FromBeta() + open class m : FromGamma() // INVISIBLE: We don't see classifiers from companions of "cousin" superclasses - open class o : FromCompanionAlpha() - open class p : FromCompanionBeta() - open class q : FromCompanionGamma() + open class o : FromCompanionAlpha() + open class p : FromCompanionBeta() + open class q : FromCompanionGamma() // DEPRECATED: Classifiers from supertypes of our own companion - open class r : FromDelta() + open class r : FromDelta() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaNew.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaNew.fir.kt index e214f8a5eff..9429c8ec7eb 100644 --- a/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaNew.fir.kt +++ b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaNew.fir.kt @@ -42,7 +42,7 @@ class Derived : Base() { syntheticProperty = 42 } - class JavaStaticInSupertypeList : Classifier() { + class JavaStaticInSupertypeList : Classifier() { } } diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaOld.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaOld.fir.kt index 9e720eb0fed..e1473cc0578 100644 --- a/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaOld.fir.kt +++ b/compiler/testData/diagnostics/tests/objects/kt21515/staticsFromJavaOld.fir.kt @@ -42,7 +42,7 @@ class Derived : Base() { syntheticProperty = 42 } - class JavaStaticInSupertypeList : Classifier() { + class JavaStaticInSupertypeList : Classifier() { } } diff --git a/compiler/testData/diagnostics/tests/regressions/kt9620.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt9620.fir.kt index 83b299cfe75..e37c2993c8e 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt9620.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt9620.fir.kt @@ -11,4 +11,4 @@ interface E2D, D<() -class M : L<C>() +class M : L<C>() diff --git a/compiler/testData/diagnostics/tests/scopes/kt1080.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt1080.fir.kt index 096aba3959c..9f25324d8df 100644 --- a/compiler/testData/diagnostics/tests/scopes/kt1080.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/kt1080.fir.kt @@ -10,7 +10,7 @@ import d import d.Test import b.d -class Some: Test() +class Some: Test() //FILE:b.kt