Refactoring. Remove isSafeCall from ResolvedCall.
This commit is contained in:
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets
|
|||||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getTargetFunctionDescriptor
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.getTargetFunctionDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.calls.ValueArgumentsToParametersMapper
|
import org.jetbrains.kotlin.resolve.calls.ValueArgumentsToParametersMapper
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.getExplicitReceiverValue
|
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.getExplicitReceiverValue
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||||
@@ -61,7 +62,7 @@ fun getReceiverTypePredicate(resolvedCall: ResolvedCall<*>, receiverValue: Recei
|
|||||||
resolvedCall.getDispatchReceiver() -> {
|
resolvedCall.getDispatchReceiver() -> {
|
||||||
val rootCallableDescriptors = callableDescriptor.findTopMostOverriddenDescriptors()
|
val rootCallableDescriptors = callableDescriptor.findTopMostOverriddenDescriptors()
|
||||||
return or(rootCallableDescriptors.mapNotNull {
|
return or(rootCallableDescriptors.mapNotNull {
|
||||||
it.getDispatchReceiverParameter()?.getType()?.let { TypeUtils.makeNullableIfNeeded(it, resolvedCall.isSafeCall()) }?.getSubtypesPredicate()
|
it.getDispatchReceiverParameter()?.getType()?.let { TypeUtils.makeNullableIfNeeded(it, resolvedCall.call.isSafeCall()) }?.getSubtypesPredicate()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.calls.callResolverUtil.*
|
|||||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS
|
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS
|
||||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode.SHAPE_FUNCTION_ARGUMENTS
|
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode.SHAPE_FUNCTION_ARGUMENTS
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.CallCandidateResolutionContext
|
import org.jetbrains.kotlin.resolve.calls.context.CallCandidateResolutionContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency.INDEPENDENT
|
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency.INDEPENDENT
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||||
@@ -79,7 +80,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes
|
|||||||
val receiverParameter = candidate.extensionReceiverParameter
|
val receiverParameter = candidate.extensionReceiverParameter
|
||||||
if (receiverArgument != null && receiverParameter != null) {
|
if (receiverArgument != null && receiverParameter != null) {
|
||||||
val receiverArgumentType = receiverArgument.type
|
val receiverArgumentType = receiverArgument.type
|
||||||
var receiverType: KotlinType? = if (context.candidateCall.isSafeCall)
|
var receiverType: KotlinType? = if (context.candidateCall.call.isSafeCall())
|
||||||
TypeUtils.makeNotNullable(receiverArgumentType)
|
TypeUtils.makeNotNullable(receiverArgumentType)
|
||||||
else
|
else
|
||||||
receiverArgumentType
|
receiverArgumentType
|
||||||
|
|||||||
-5
@@ -110,11 +110,6 @@ public abstract class DelegatingResolvedCall<D extends CallableDescriptor> imple
|
|||||||
return resolvedCall.getDataFlowInfoForArguments();
|
return resolvedCall.getDataFlowInfoForArguments();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSafeCall() {
|
|
||||||
return resolvedCall.isSafeCall();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public KotlinType getSmartCastDispatchReceiverType() {
|
public KotlinType getSmartCastDispatchReceiverType() {
|
||||||
|
|||||||
@@ -79,8 +79,6 @@ public interface ResolvedCall<D extends CallableDescriptor> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
DataFlowInfoForArguments getDataFlowInfoForArguments();
|
DataFlowInfoForArguments getDataFlowInfoForArguments();
|
||||||
|
|
||||||
boolean isSafeCall();
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
KotlinType getSmartCastDispatchReceiverType();
|
KotlinType getSmartCastDispatchReceiverType();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.psi.Call;
|
|||||||
import org.jetbrains.kotlin.psi.ValueArgument;
|
import org.jetbrains.kotlin.psi.ValueArgument;
|
||||||
import org.jetbrains.kotlin.resolve.DelegatingBindingTrace;
|
import org.jetbrains.kotlin.resolve.DelegatingBindingTrace;
|
||||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.CallResolverUtilKt;
|
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.CallResolverUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem;
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem;
|
||||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
|
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind;
|
||||||
@@ -348,11 +347,6 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableRe
|
|||||||
return typeArguments;
|
return typeArguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSafeCall() {
|
|
||||||
return CallUtilKt.isSafeCall(call);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public MutableDataFlowInfoForArguments getDataFlowInfoForArguments() {
|
public MutableDataFlowInfoForArguments getDataFlowInfoForArguments() {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
|||||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||||
import org.jetbrains.kotlin.psi.KtThisExpression
|
import org.jetbrains.kotlin.psi.KtThisExpression
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.CallResolutionContext
|
import org.jetbrains.kotlin.resolve.calls.context.CallResolutionContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||||
@@ -78,7 +79,7 @@ fun ResolvedCall<*>.getImplicitReceiverValue(): ReceiverValue? {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun ResolvedCall<*>.hasSafeNullableReceiver(context: CallResolutionContext<*>): Boolean {
|
private fun ResolvedCall<*>.hasSafeNullableReceiver(context: CallResolutionContext<*>): Boolean {
|
||||||
if (!isSafeCall) return false
|
if (!call.isSafeCall()) return false
|
||||||
val receiverValue = getExplicitReceiverValue()?.let { DataFlowValueFactory.createDataFlowValue(it, context) }
|
val receiverValue = getExplicitReceiverValue()?.let { DataFlowValueFactory.createDataFlowValue(it, context) }
|
||||||
?: return false
|
?: return false
|
||||||
return context.dataFlowInfo.getPredictableNullability(receiverValue).canBeNull()
|
return context.dataFlowInfo.getPredictableNullability(receiverValue).canBeNull()
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||||
@@ -262,7 +263,7 @@ class KotlinPsiUnifier(
|
|||||||
!checkSpecialOperations() -> UNMATCHED
|
!checkSpecialOperations() -> UNMATCHED
|
||||||
!matchDescriptors(rc1.candidateDescriptor, rc2.candidateDescriptor) -> UNMATCHED
|
!matchDescriptors(rc1.candidateDescriptor, rc2.candidateDescriptor) -> UNMATCHED
|
||||||
!checkReceivers() -> UNMATCHED
|
!checkReceivers() -> UNMATCHED
|
||||||
rc1.isSafeCall != rc2.isSafeCall -> UNMATCHED
|
rc1.call.isSafeCall() != rc2.call.isSafeCall() -> UNMATCHED
|
||||||
else -> {
|
else -> {
|
||||||
val s = checkTypeArguments()
|
val s = checkTypeArguments()
|
||||||
if (s != MATCHED) s else checkArguments()
|
if (s != MATCHED) s else checkArguments()
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.js.translate.reference.CallArgumentTranslator
|
|||||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||||
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils.getReceiverParameterForReceiver
|
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils.getReceiverParameterForReceiver
|
||||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils
|
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.*
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.*
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||||
@@ -126,7 +127,7 @@ private fun TranslationContext.createCallInfo(resolvedCall: ResolvedCall<out Cal
|
|||||||
var extensionReceiver = getExtensionReceiver()
|
var extensionReceiver = getExtensionReceiver()
|
||||||
var notNullConditional: JsConditional? = null
|
var notNullConditional: JsConditional? = null
|
||||||
|
|
||||||
if (resolvedCall.isSafeCall) {
|
if (resolvedCall.call.isSafeCall()) {
|
||||||
when (resolvedCall.explicitReceiverKind) {
|
when (resolvedCall.explicitReceiverKind) {
|
||||||
BOTH_RECEIVERS, EXTENSION_RECEIVER -> {
|
BOTH_RECEIVERS, EXTENSION_RECEIVER -> {
|
||||||
notNullConditional = TranslationUtils.notNullConditional(extensionReceiver!!, JsLiteral.NULL, this)
|
notNullConditional = TranslationUtils.notNullConditional(extensionReceiver!!, JsLiteral.NULL, this)
|
||||||
|
|||||||
Reference in New Issue
Block a user