From ac507e721cd448342e0dc5732f2d651f4553e9a6 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Mon, 3 Jul 2017 20:48:39 +0300 Subject: [PATCH] [NI] Do not add non-dynamic candidates when there is dynamic extension --- .../calls/model/KotlinResolverContext.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt index bbfc3b7e479..52e7cf192b0 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt @@ -22,13 +22,12 @@ import org.jetbrains.kotlin.resolve.calls.components.* import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolver import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind -import org.jetbrains.kotlin.resolve.calls.tower.CandidateFactory -import org.jetbrains.kotlin.resolve.calls.tower.CandidateWithBoundDispatchReceiver -import org.jetbrains.kotlin.resolve.calls.tower.HiddenDescriptor -import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower +import org.jetbrains.kotlin.resolve.calls.tower.* +import org.jetbrains.kotlin.resolve.descriptorUtil.hasDynamicExtensionAnnotation import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.TypeSubstitutor +import org.jetbrains.kotlin.types.isDynamic class KotlinCallContext( @@ -82,6 +81,16 @@ class SimpleCandidateFactory(val callContext: KotlinCallContext, val kotlinCall: candidateDiagnostics.add(HiddenDescriptor) } + if (extensionReceiver != null) { + val parameterIsDynamic = towerCandidate.descriptor.extensionReceiverParameter!!.value.type.isDynamic() + val argumentIsDynamic = extensionReceiver.receiverValue.type.isDynamic() + + if (parameterIsDynamic != argumentIsDynamic || + (parameterIsDynamic && !towerCandidate.descriptor.hasDynamicExtensionAnnotation())) { + candidateDiagnostics.add(HiddenExtensionRelatedToDynamicTypes) + } + } + return SimpleKotlinResolutionCandidate(callContext, kotlinCall, explicitReceiverKind, dispatchArgumentReceiver, extensionArgumentReceiver, towerCandidate.descriptor, null, candidateDiagnostics) }