From 6dd9115ee9472ec64800530ad8b05422aaa3c376 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 9 Aug 2022 22:16:11 +0200 Subject: [PATCH] FE1.0 Analysis API: Fix kind in implicit smart-casts info --- .../components/KtFe10SmartCastProvider.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10SmartCastProvider.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10SmartCastProvider.kt index 69f6db5d453..fd385c7a8d9 100644 --- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10SmartCastProvider.kt +++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KtFe10SmartCastProvider.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.smartcasts.ExplicitSmartCasts import org.jetbrains.kotlin.resolve.calls.smartcasts.MultipleSmartCasts +import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.checker.intersectWrappedTypes internal class KtFe10SmartCastProvider( @@ -51,12 +52,19 @@ internal class KtFe10SmartCastProvider( return defaultType?.toKtType(analysisContext) } + private fun smartCastedImplicitReceiver(type: KotlinType?, kind: KtImplicitReceiverSmartCastKind): KtImplicitReceiverSmartCast? { + if (type == null) return null + return KtImplicitReceiverSmartCast(type.toKtType(analysisContext), kind, token) + } + override fun getImplicitReceiverSmartCast(expression: KtExpression): Collection { val bindingContext = analysisContext.analyze(expression) val smartCasts = bindingContext[BindingContext.IMPLICIT_RECEIVER_SMARTCAST, expression] ?: return emptyList() - return smartCasts.receiverTypes.map { (_, type) -> - val kind = KtImplicitReceiverSmartCastKind.DISPATCH // TODO provide precise kind - KtImplicitReceiverSmartCast(type.toKtType(analysisContext), kind, token) - } + val call = bindingContext[BindingContext.CALL, expression] ?: return emptyList() + val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, call] ?: return emptyList() + return listOfNotNull( + smartCastedImplicitReceiver(smartCasts.receiverTypes[resolvedCall.dispatchReceiver], KtImplicitReceiverSmartCastKind.DISPATCH), + smartCastedImplicitReceiver(smartCasts.receiverTypes[resolvedCall.extensionReceiver], KtImplicitReceiverSmartCastKind.EXTENSION) + ) } } \ No newline at end of file