From b1d17cfd7bb73fe533a58f183d5a4ac1c2277678 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Thu, 22 Jul 2021 13:48:50 +0300 Subject: [PATCH] [FE 1.0] Force resolve annotations on type arguments ^KT-46173 --- .../org/jetbrains/kotlin/resolve/AnnotationChecker.kt | 9 +++++++++ .../notLinked/annotations/type-annotations/neg/2.kt | 2 +- .../notLinked/annotations/type-annotations/neg/7.kt | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt index ee733314a51..97785e7575a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationChecker.kt @@ -158,6 +158,15 @@ class AnnotationChecker( val shouldRunCheck = isSuperType || shouldCheckReferenceItself if (shouldRunCheck) { for (entry in reference.annotationEntries) { + val descriptor = trace.get(BindingContext.ANNOTATION, entry) + if (descriptor is LazyAnnotationDescriptor) { + /* + * There are no users of type annotations until backend, so if there are errors + * in annotation call then we should force resolve of it to detect and + * report them + */ + descriptor.forceResolveAllContents() + } val actualTargets = getActualTargetList(reference, null, trace.bindingContext) if (entry.useSiteTarget != null && isSuperType) { val reportError = languageVersionSettings.supportsFeature(ProhibitUseSiteTargetAnnotationsOnSuperTypes) diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/2.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/2.kt index 376f3965e61..bd29b800254 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/2.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/2.kt @@ -14,4 +14,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/7.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.kt index f037f2b3251..10fcb3a938c 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.kt @@ -18,7 +18,7 @@ annotation class Ann */ open class TypeToken -val case_1 = object : TypeToken<@Ann(unresolved_reference) String>() {} +val case_1 = object : TypeToken<@Ann(unresolved_reference) String>() {} /* * TESTCASE NUMBER: 2 @@ -26,4 +26,4 @@ val case_1 = object : TypeToken<@Ann(Ann(unresolved_reference) A {} +val case_2 = object: @Ann(unresolved_reference) A {}