From 8fd087a96446715ead6a9eca2451edee46765660 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 3 Aug 2020 11:02:26 +0300 Subject: [PATCH] [FIR] Don't report duplicated UNRESOLVED_REFERENCE on annotation entries --- .../ErrorNodeDiagnosticCollectorComponent.kt | 3 +++ .../annotations/AmbigiousAnnotationConstructor.fir.kt | 4 ++-- .../tests/annotations/AnnotationIdentifier.fir.kt | 4 ++-- .../tests/annotations/NonAnnotationClass.fir.kt | 2 +- .../RecursivelyIncorrectlyAnnotatedParameter.fir.kt | 2 +- .../tests/annotations/kt1860-negative.fir.kt | 8 ++++---- .../tests/annotations/typeParameterAsAnnotation.fir.kt | 4 ++-- .../tests/annotations/unresolvedReferenceRange.fir.kt | 10 +++++----- .../tests/localClasses/localAnnotationClass.fir.kt | 2 +- .../localClasses/localAnnotationClassError.fir.kt | 2 +- .../tests/modifiers/IllegalModifiers.fir.kt | 2 +- .../tests/objects/kt21515/annotationConstructor.fir.kt | 2 +- 12 files changed, 24 insertions(+), 21 deletions(-) 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 9d688e4b7f5..355c39edb78 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 @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.analysis.collectors.components +import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.fir.FirFakeSourceElementKind import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext @@ -50,6 +51,8 @@ class ErrorNodeDiagnosticCollectorComponent(collector: AbstractDiagnosticCollect override fun visitErrorNamedReference(errorNamedReference: FirErrorNamedReference, data: CheckerContext) { val source = errorNamedReference.source ?: return + // Don't report duplicated unresolved reference on annotation entry (already reported on its type) + if (source.elementType == KtNodeTypes.ANNOTATION_ENTRY && errorNamedReference.diagnostic is ConeUnresolvedNameError) return runCheck { reportFirDiagnostic(errorNamedReference.diagnostic, source, it) } } diff --git a/compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.fir.kt b/compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.fir.kt index c4b1279115c..13e7ab907b6 100644 --- a/compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/AmbigiousAnnotationConstructor.fir.kt @@ -1,6 +1,6 @@ // !WITH_NEW_INFERENCE import java.util.ArrayList -@ArrayList(1, 1) fun b() {} -@Xoo(x) fun c() {} +@ArrayList(1, 1) fun b() {} +@Xoo(x) fun c() {} @java.lang.Deprecated(x) fun a() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotationIdentifier.fir.kt b/compiler/testData/diagnostics/tests/annotations/AnnotationIdentifier.fir.kt index 8de25b7cb85..02bc1bbb3c1 100644 --- a/compiler/testData/diagnostics/tests/annotations/AnnotationIdentifier.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/AnnotationIdentifier.fir.kt @@ -6,7 +6,7 @@ annotation class annotation package test -@test.annotation class annotation +@test.annotation class annotation // FILE: other/c.kt @@ -14,6 +14,6 @@ package other annotation class My -@test.annotation class Your +@test.annotation class Your @My class Our diff --git a/compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.fir.kt b/compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.fir.kt index e13d425e5de..bd22d122e7b 100644 --- a/compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.fir.kt @@ -1,3 +1,3 @@ class Foo -@Foo class Bar +@Foo class Bar diff --git a/compiler/testData/diagnostics/tests/annotations/RecursivelyIncorrectlyAnnotatedParameter.fir.kt b/compiler/testData/diagnostics/tests/annotations/RecursivelyIncorrectlyAnnotatedParameter.fir.kt index ac0f92b7fcf..cb60f1f1d27 100644 --- a/compiler/testData/diagnostics/tests/annotations/RecursivelyIncorrectlyAnnotatedParameter.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/RecursivelyIncorrectlyAnnotatedParameter.fir.kt @@ -1,2 +1,2 @@ // Class constructor parameter CAN be recursively annotated -class RecursivelyAnnotated(@RecursivelyAnnotated(1) val x: Int) +class RecursivelyAnnotated(@RecursivelyAnnotated(1) val x: Int) diff --git a/compiler/testData/diagnostics/tests/annotations/kt1860-negative.fir.kt b/compiler/testData/diagnostics/tests/annotations/kt1860-negative.fir.kt index c5acecfd484..ab8959e75ae 100644 --- a/compiler/testData/diagnostics/tests/annotations/kt1860-negative.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/kt1860-negative.fir.kt @@ -1,10 +1,10 @@ // !WITH_NEW_INFERENCE -fun foo(@varargs f : Int) {} +fun foo(@varargs f : Int) {} var bar : Int = 1 - set(@varargs v) {} + set(@varargs v) {} -val x : (Int) -> Int = {@varargs x : Int -> x} +val x : (Int) -> Int = {@varargs x : Int -> x} -class Hello(@varargs args: Any) { +class Hello(@varargs args: Any) { } diff --git a/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.fir.kt b/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.fir.kt index f070776dbbf..1290a11601f 100644 --- a/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.fir.kt @@ -1,9 +1,9 @@ class Foo { - @T + @T fun foo() = 0 } class Bar { - @T + @T fun foo() = 0 } diff --git a/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.fir.kt b/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.fir.kt index 9e38b3185b2..060d89e47f1 100644 --- a/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.fir.kt +++ b/compiler/testData/diagnostics/tests/annotations/unresolvedReferenceRange.fir.kt @@ -1,5 +1,5 @@ -@Ann class A -@Ann class B -@Ann(1) class C -@kotlin.Ann(1) class D -@kotlin.annotation.Ann(1) class E \ No newline at end of file +@Ann class A +@Ann class B +@Ann(1) class C +@kotlin.Ann(1) class D +@kotlin.annotation.Ann(1) class E \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/localClasses/localAnnotationClass.fir.kt b/compiler/testData/diagnostics/tests/localClasses/localAnnotationClass.fir.kt index 6ec90129200..816f17a81b1 100644 --- a/compiler/testData/diagnostics/tests/localClasses/localAnnotationClass.fir.kt +++ b/compiler/testData/diagnostics/tests/localClasses/localAnnotationClass.fir.kt @@ -3,7 +3,7 @@ fun f() { annotation class Anno - @Anno class Local { + @Anno class Local { annotation class Nested } } diff --git a/compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.fir.kt b/compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.fir.kt index f40d3f357f9..6237efead02 100644 --- a/compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.fir.kt +++ b/compiler/testData/diagnostics/tests/localClasses/localAnnotationClassError.fir.kt @@ -3,7 +3,7 @@ fun f() { annotation class Anno - @Anno class Local { + @Anno class Local { annotation class Nested } } diff --git a/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.fir.kt b/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.fir.kt index 749121c7c27..32ff714f8dd 100644 --- a/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.fir.kt +++ b/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.fir.kt @@ -1,4 +1,4 @@ -@myAnnotation public +@myAnnotation public package illegal_modifiers abstract class A() { diff --git a/compiler/testData/diagnostics/tests/objects/kt21515/annotationConstructor.fir.kt b/compiler/testData/diagnostics/tests/objects/kt21515/annotationConstructor.fir.kt index 77f471615b6..81e54e4186d 100644 --- a/compiler/testData/diagnostics/tests/objects/kt21515/annotationConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/objects/kt21515/annotationConstructor.fir.kt @@ -8,6 +8,6 @@ open class Base { class Derived : Base() { - @Foo + @Foo fun foo() = 42 }