From 1835185b1693bf48b64a569f2162d4cff6922379 Mon Sep 17 00:00:00 2001 From: Mark Punzalan Date: Tue, 20 Apr 2021 08:29:14 +0000 Subject: [PATCH] FIR: Remove duplicated diagnostics on annotations on types. --- .../RedundantReturnUnitTypeChecker.kt | 2 +- .../collectors/AbstractDiagnosticCollectorVisitor.kt | 7 ++++++- .../tests/annotations/typeUse/kt25876.fir.kt | 6 +++--- .../tests/annotations/typeUse/kt46173.fir.kt | 2 +- .../tests/annotations/typeUse/kt8325.fir.kt | 6 ------ .../diagnostics/tests/annotations/typeUse/kt8325.kt | 1 + .../suspendFunctionType/modifierApplicability.fir.kt | 4 ++-- .../annotations/type-annotations/neg/1.fir.kt | 7 ------- .../notLinked/annotations/type-annotations/neg/1.kt | 1 + .../annotations/type-annotations/neg/2.fir.kt | 2 +- .../annotations/type-annotations/neg/3.fir.kt | 4 ++-- .../annotations/type-annotations/neg/5.fir.kt | 2 +- .../annotations/type-annotations/neg/6.fir.kt | 8 ++++---- .../annotations/type-annotations/neg/7.fir.kt | 2 +- .../annotations/type-annotations/neg/8.fir.kt | 11 ----------- .../notLinked/annotations/type-annotations/neg/8.kt | 1 + .../annotations/type-annotations/neg/9.fir.kt | 12 ------------ .../notLinked/annotations/type-annotations/neg/9.kt | 1 + 18 files changed, 26 insertions(+), 53 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/annotations/typeUse/kt8325.fir.kt delete mode 100644 compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/1.fir.kt delete mode 100644 compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/8.fir.kt delete mode 100644 compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/9.fir.kt diff --git a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantReturnUnitTypeChecker.kt b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantReturnUnitTypeChecker.kt index 18f8788142f..635831e997f 100644 --- a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantReturnUnitTypeChecker.kt +++ b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantReturnUnitTypeChecker.kt @@ -5,7 +5,7 @@ interface I { } class A { - fun too(): @Annotation Unit {} + fun too(): @Annotation Unit {} fun foo(): Unit { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt index 458f2242796..6134d583295 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt @@ -162,7 +162,12 @@ abstract class AbstractDiagnosticCollectorVisitor( } override fun visitResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef, data: Nothing?) { - super.visitResolvedTypeRef(resolvedTypeRef, data) + // Assuming no errors, the children of FirResolvedTypeRef (currently this can be FirAnnotationCalls) will also be present + // as children in delegatedTypeRef. We should make sure those elements are only visited once, otherwise diagnostics will be + // collected twice: once through resolvedTypeRef's children and another through resolvedTypeRef.delegatedTypeRef's children. + if (resolvedTypeRef.type is ConeClassErrorType) { + super.visitResolvedTypeRef(resolvedTypeRef, data) + } resolvedTypeRef.delegatedTypeRef?.accept(this, data) } diff --git a/compiler/testData/diagnostics/tests/annotations/typeUse/kt25876.fir.kt b/compiler/testData/diagnostics/tests/annotations/typeUse/kt25876.fir.kt index fcb75ef2732..866e5f81fe9 100644 --- a/compiler/testData/diagnostics/tests/annotations/typeUse/kt25876.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/typeUse/kt25876.fir.kt @@ -4,10 +4,10 @@ @Target(AnnotationTarget.TYPE) annotation class Anno(val value: String) -fun foo(x: String): @Anno(Lorem, ipsum::class, "dolor", sit-amet) String { // OK +fun foo(x: String): @Anno(Lorem, ipsum::class, "dolor", sit-amet) String { // OK return x } -abstract class Foo : @Anno(o_O) Throwable() // OK +abstract class Foo : @Anno(o_O) Throwable() // OK -abstract class BarO_o) Any> // OK +abstract class BarO_o) Any> // OK diff --git a/compiler/testData/diagnostics/tests/annotations/typeUse/kt46173.fir.kt b/compiler/testData/diagnostics/tests/annotations/typeUse/kt46173.fir.kt index 35c06313357..0455c98ac13 100644 --- a/compiler/testData/diagnostics/tests/annotations/typeUse/kt46173.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/typeUse/kt46173.fir.kt @@ -6,5 +6,5 @@ annotation class Ann(val s: String) fun some(): Int { - return 1 as @Ann(6) Int // should error but doesn't + return 1 as @Ann(6) Int // should error but doesn't } diff --git a/compiler/testData/diagnostics/tests/annotations/typeUse/kt8325.fir.kt b/compiler/testData/diagnostics/tests/annotations/typeUse/kt8325.fir.kt deleted file mode 100644 index d4fc6913762..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/typeUse/kt8325.fir.kt +++ /dev/null @@ -1,6 +0,0 @@ -// !LANGUAGE: +ProperCheckAnnotationsTargetInTypeUsePositions -// ISSUE: KT-8325 - -fun foo() { - object : @__UNRESOLVED__ Any() {} -} diff --git a/compiler/testData/diagnostics/tests/annotations/typeUse/kt8325.kt b/compiler/testData/diagnostics/tests/annotations/typeUse/kt8325.kt index 1d6ed561160..2007916fce8 100644 --- a/compiler/testData/diagnostics/tests/annotations/typeUse/kt8325.kt +++ b/compiler/testData/diagnostics/tests/annotations/typeUse/kt8325.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +ProperCheckAnnotationsTargetInTypeUsePositions // ISSUE: KT-8325 diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.fir.kt index e39f7d145d3..3960cbf4e6a 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendFunctionType/modifierApplicability.fir.kt @@ -22,8 +22,8 @@ typealias Test15 = (@A() suspend () -> Unit)? typealias Test16 = (@A suspend () -> Unit)? typealias Test17 = @A suspend RS.() -> Unit typealias Test18 = (suspend () -> Unit)? -typealias Test19 = (@A({ val x: suspend String? = null; "" }()) suspend () -> Unit)? -typealias Test20 = (@A("".let { val x: suspend String? = null; it }) suspend () -> Unit)? +typealias Test19 = (@A({ val x: suspend String? = null; "" }()) suspend () -> Unit)? +typealias Test20 = (@A("".let { val x: suspend String? = null; it }) suspend () -> Unit)? interface Supertype1 : suspend () -> Unit { diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/1.fir.kt deleted file mode 100644 index c4540a6889d..00000000000 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/1.fir.kt +++ /dev/null @@ -1,7 +0,0 @@ -// TESTCASE NUMBER: 1 -@Target(AnnotationTarget.TYPE) -annotation class Ann(val x: Int) - -fun case_1(x: String): @Ann(unresolved_reference) String { - return x -} diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/1.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/1.kt index 39f30453daa..f9f62995a82 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/1.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/1.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL /* * KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (NEGATIVE) * diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/2.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/2.fir.kt index 3eb92eadf7a..0d05435d922 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/2.fir.kt @@ -5,4 +5,4 @@ @Target(AnnotationTarget.TYPE) annotation class Ann(val x: Int) -abstract class Foo : @Ann(unresolved_reference) Any() +abstract class Foo : @Ann(unresolved_reference) Any() diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/3.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/3.fir.kt index b8ec19d447f..2ac0950b2b2 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/3.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/3.fir.kt @@ -8,7 +8,7 @@ annotation class Ann(val x: Int) fun foo(i: Inv<@Ann(unresolved_reference) String>) {} // TESTCASE NUMBER: 2 -fun test(vararg a: @Ann(unresolved_reference) Any) {} +fun test(vararg a: @Ann(unresolved_reference) Any) {} // TESTCASE NUMBER: 3 -class A(a: @Ann(unresolved_reference) T) +class A(a: @Ann(unresolved_reference) T) diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/5.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/5.fir.kt index e1342e91f10..a586eedc3be 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/5.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/5.fir.kt @@ -3,7 +3,7 @@ annotation class Ann(val x: Int) // TESTCASE NUMBER: 1 -abstract class Barunresolved_reference) Any> +abstract class Barunresolved_reference) Any> /* * TESTCASE NUMBER: 2 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/6.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/6.fir.kt index 88f1d452c1b..623c64e2f89 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/6.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/6.fir.kt @@ -10,7 +10,7 @@ annotation class Ann(val x: Int) * UNEXPECTED BEHAVIOUR */ fun case_1(a: Any) { - if (a is @Ann(unresolved_reference) String) return + if (a is @Ann(unresolved_reference) String) return } /* @@ -18,7 +18,7 @@ fun case_1(a: Any) { * UNEXPECTED BEHAVIOUR */ fun case_2(a: Any) { - a as @Ann(unresolved_reference) String // OK, no error in IDE and in the compiler + a as @Ann(unresolved_reference) String // OK, no error in IDE and in the compiler } /* @@ -28,10 +28,10 @@ fun case_2(a: Any) { fun case_3_1(a: Any) {} fun case_3_2(a: Any) { - case_3_1(a as @Ann(unresolved_reference) String) // OK, no error in IDE and in the compiler + case_3_1(a as @Ann(unresolved_reference) String) // OK, no error in IDE and in the compiler } // TESTCASE NUMBER: 4 fun case_4(a: Any) { - val x = a as @Ann(unresolved_reference) String // ERROR, has error in IDE and in the compiler + val x = a as @Ann(unresolved_reference) String // ERROR, has error in IDE and in the compiler } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.fir.kt index 73f8301e2e2..6c991d298d1 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.fir.kt @@ -18,4 +18,4 @@ val case_1 = object : TypeToken<@Ann(unresolved_reference) String>() {} */ interface A -val case_2 = object: @Ann(unresolved_reference) A {} +val case_2 = object: @Ann(unresolved_reference) A {} diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/8.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/8.fir.kt deleted file mode 100644 index 0a265254b36..00000000000 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/8.fir.kt +++ /dev/null @@ -1,11 +0,0 @@ -// TESTCASE NUMBER: 1, 2 -@Target(AnnotationTarget.TYPE) -annotation class Ann(val x: Int) - -// TESTCASE NUMBER: 1 -val @Ann(unresolved_reference) T.test // OK, error only in IDE but not in the compiler - get() = 10 - -// TESTCASE NUMBER: 2 -val @Ann(unresolved_reference) Int.test - get() = 10 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/8.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/8.kt index c33a4d7471c..a6432af194b 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/8.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/8.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL /* * KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (NEGATIVE) * diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/9.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/9.fir.kt deleted file mode 100644 index db0b8962d0a..00000000000 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/9.fir.kt +++ /dev/null @@ -1,12 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -/* - * TESTCASE NUMBER: 1 - * UNEXPECTED BEHAVIOUR - */ -@Target(AnnotationTarget.TYPE) -annotation class Ann - -var T.test - get() = 11 - set(value: @Ann(unresolved_reference) Int) {} diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/9.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/9.kt index 916806c465c..3c5c1f0c6ef 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/9.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/9.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER /*