From 5afebb4e789607109ffc18942f747b73fbdb3a9d Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Thu, 14 Jan 2021 16:26:35 +0300 Subject: [PATCH] FIR: Transform synthetic calls children even without incomplete candidate It might be necessary for cases like run @l1{ run { if (...) return@l1 1 } } "if" is a synthetic call, but without candidate since there's just one branch But return@l1 1 is incomplete because it's resolved in dependent context and "1" is hang incomplete integer literal --- .../FirCallCompletionResultsWriterTransformer.kt | 11 +++++++++-- .../tests/inference/regressions/kt36342_2.fir.kt | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index 63e080d5868..e801a3062b0 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -534,9 +534,16 @@ class FirCallCompletionResultsWriterTransformer( syntheticCall: D, data: ExpectedArgumentType?, ): CompositeTransformResult where D : FirResolvable, D : FirExpression { - val calleeReference = syntheticCall.calleeReference as? FirNamedReferenceWithCandidate ?: return syntheticCall.compose() + val calleeReference = syntheticCall.calleeReference as? FirNamedReferenceWithCandidate + val declaration = calleeReference?.candidate?.symbol?.fir as? FirSimpleFunction - val declaration = calleeReference.candidate.symbol.fir as? FirSimpleFunction ?: return syntheticCall.compose() + if (calleeReference == null || declaration == null) { + syntheticCall.transformChildren( + this, + data = data?.getExpectedType(syntheticCall)?.toExpectedType() ?: syntheticCall.typeRef.coneType.toExpectedType() + ) + return syntheticCall.compose() + } val typeRef = typeCalculator.tryCalculateReturnType(declaration) syntheticCall.replaceTypeRefWithSubstituted(calleeReference, typeRef) diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt36342_2.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt36342_2.fir.kt index 4657de5aa65..5e8254c4013 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt36342_2.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt36342_2.fir.kt @@ -5,7 +5,7 @@ fun materialize(): M = TODO() fun test(b: Boolean) { id(if (b) { - id(unresolved) + id(unresolved) } else { id( materialize()