From 462687ed66cc2d0927234dd486bf04731196fbb0 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Mon, 11 Sep 2023 15:35:30 +0200 Subject: [PATCH] [FIR] Don't resolve call in annotation arguments phase if receiver type isn't resolved This prevents exceptions from being thrown during resolution of red code because FirExpression.resolvedType is called but during annotation arguments phase we don't have return types for implicitly typed declarations. #KT-61367 --- .../src/org/jetbrains/kotlin/fir/FirCallResolver.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt index 7e698125f41..e04cd4ca500 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt @@ -247,6 +247,16 @@ class FirCallResolver( @Suppress("NAME_SHADOWING") val qualifiedAccess = qualifiedAccess.let(transformer::transformExplicitReceiver) + + // In red code, annotations can call arbitrary non-const declarations. + // During annotation arguments phase, we exit out if the receiver has unresolved type so that we don't throw exceptions. + // During body resolve, we will report something like ANNOTATION_ARGUMENT_MUST_BE_CONST. + if (transformer.baseTransformerPhase == FirResolvePhase.ARGUMENTS_OF_ANNOTATIONS && + qualifiedAccess.explicitReceiver?.isResolved == false + ) { + return qualifiedAccess + } + val nonFatalDiagnosticFromExpression = (qualifiedAccess as? FirPropertyAccessExpression)?.nonFatalDiagnostics val basicResult by lazy(LazyThreadSafetyMode.NONE) {