From c88b4105c50fd7c28d42af2d5109afd39f7d8763 Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Mon, 18 Sep 2023 17:16:16 +0200 Subject: [PATCH] [K2] Correctly handle case when expect annotation is unresolved Don't report if annotation has error type. Review: KT-MR-12250 ^KT-62026 Fixed --- .../mpp/FirExpectActualMatchingContextImpl.kt | 13 ++++++++++--- .../annotationMatching/unresolvedReference.fir.kt | 9 --------- .../annotationMatching/unresolvedReference.kt | 1 + 3 files changed, 11 insertions(+), 12 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/multiplatform/annotationMatching/unresolvedReference.fir.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContextImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContextImpl.kt index 690609239b0..79dfdb2b905 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContextImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContextImpl.kt @@ -27,7 +27,6 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualCollectionArgumentsCompatibilityCheckStrategy import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualMatchingContext.AnnotationCallInfo -import org.jetbrains.kotlin.mpp.SourceElementMarker import org.jetbrains.kotlin.resolve.checkers.OptInNames import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility import org.jetbrains.kotlin.types.AbstractTypeChecker @@ -388,7 +387,7 @@ class FirExpectActualMatchingContextImpl private constructor( override val annotationSymbol: FirAnnotation = annotation override val classId: ClassId? - get() = annotation.toAnnotationClassId(actualSession) + get() = getAnnotationConeType()?.lookupTag?.classId override val isRetentionSource: Boolean get() = getAnnotationClass()?.getRetention(actualSession) == AnnotationRetention.SOURCE @@ -397,7 +396,15 @@ class FirExpectActualMatchingContextImpl private constructor( get() = getAnnotationClass()?.hasAnnotation(OptInNames.REQUIRES_OPT_IN_CLASS_ID, actualSession) ?: false private fun getAnnotationClass(): FirRegularClassSymbol? = - annotation.annotationTypeRef.coneType.toRegularClassSymbol(actualSession) + getAnnotationConeType()?.toRegularClassSymbol(actualSession) + + private fun getAnnotationConeType(): ConeClassLikeType? { + val coneType = annotation.toAnnotationClassLikeType(actualSession) + if (coneType is ConeErrorType) { + return null + } + return coneType + } } override val DeclarationSymbolMarker.hasSourceAnnotationsErased: Boolean diff --git a/compiler/testData/diagnostics/tests/multiplatform/annotationMatching/unresolvedReference.fir.kt b/compiler/testData/diagnostics/tests/multiplatform/annotationMatching/unresolvedReference.fir.kt deleted file mode 100644 index 1b09ad7bb56..00000000000 --- a/compiler/testData/diagnostics/tests/multiplatform/annotationMatching/unresolvedReference.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -// DIAGNOSTICS: -UNRESOLVED_REFERENCE -// MODULE: m1-common -// FILE: common.kt -@NonExistingClass -expect fun foo() - -// MODULE: m1-jvm()()(m1-common) -// FILE: jvm.kt -actual fun foo() {} diff --git a/compiler/testData/diagnostics/tests/multiplatform/annotationMatching/unresolvedReference.kt b/compiler/testData/diagnostics/tests/multiplatform/annotationMatching/unresolvedReference.kt index 3e56ba789c7..896fbb52a1d 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/annotationMatching/unresolvedReference.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/annotationMatching/unresolvedReference.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // DIAGNOSTICS: -UNRESOLVED_REFERENCE // MODULE: m1-common // FILE: common.kt