From 031027273820b9271dee39344538f74788ca4bfa Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 17 Sep 2020 18:27:06 +0300 Subject: [PATCH] FIR: perform more proper type approximation in completion Note: test data change is questionable here --- .../FirCallCompletionResultsWriterTransformer.kt | 9 ++++----- .../diagnostics/tests/j+k/wrongVarianceInJava.fir.kt | 4 ++-- 2 files changed, 6 insertions(+), 7 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 d4629c07fd9..ab4ae4309ec 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 @@ -260,11 +260,10 @@ class FirCallCompletionResultsWriterTransformer( candidate: Candidate, ): FirResolvedTypeRef { val initialType = candidate.substitutor.substituteOrSelf(type) - val finalType = finalSubstitutor.substituteOrNull(initialType)?.let { substitutedType -> - typeApproximator.approximateToSuperType( - substitutedType, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference, - ) as ConeKotlinType? ?: substitutedType - } + val substitutedType = finalSubstitutor.substituteOrNull(initialType) + val finalType = typeApproximator.approximateToSuperType( + type = substitutedType ?: initialType, TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference, + ) as ConeKotlinType? ?: substitutedType return withReplacedConeType(finalType) } diff --git a/compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt b/compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt index 0c3a1fd26da..29911c2d792 100644 --- a/compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/wrongVarianceInJava.fir.kt @@ -19,6 +19,6 @@ class In { } fun test() { - A.foo().x() checkType { _() } - A.bar().y(null) + A.foo().x() checkType { _() } + A.bar().y(null) }