Report MEMBER_PROJECTED_OUT on calls with smart cast receiver
#KT-10856 Fixed
This commit is contained in:
@@ -61,7 +61,9 @@ fun ResolutionContext<*>.reportTypeMismatchDueToTypeProjection(
|
||||
is CallPosition.Unknown -> return false
|
||||
}
|
||||
|
||||
val receiverType = resolvedCall.dispatchReceiver?.type ?: return false
|
||||
val receiverType = resolvedCall.smartCastDispatchReceiverType
|
||||
?: (resolvedCall.dispatchReceiver ?: return false).type
|
||||
|
||||
val callableDescriptor = resolvedCall.resultingDescriptor.original
|
||||
|
||||
val substitutedDescriptor =
|
||||
|
||||
@@ -436,7 +436,7 @@ class CandidateResolver(
|
||||
}
|
||||
|
||||
private fun <D : CallableDescriptor> CallCandidateResolutionContext<D>.checkReceiver(
|
||||
candidateCall: ResolvedCall<D>,
|
||||
candidateCall: MutableResolvedCall<D>,
|
||||
receiverParameter: ReceiverParameterDescriptor?,
|
||||
receiverArgument: ReceiverValue?,
|
||||
isExplicitReceiver: Boolean,
|
||||
@@ -497,9 +497,12 @@ class CandidateResolver(
|
||||
if (smartCastResult == null) {
|
||||
reportUnsafeCall = true
|
||||
}
|
||||
else if (!smartCastResult.isCorrect) {
|
||||
// Error about unstable smart cast reported within checkAndRecordPossibleCast
|
||||
return OTHER_ERROR
|
||||
else {
|
||||
candidateCall.setSmartCastDispatchReceiverType(smartCastResult.resultType)
|
||||
if (!smartCastResult.isCorrect) {
|
||||
// Error about unstable smart cast reported within checkAndRecordPossibleCast
|
||||
return OTHER_ERROR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -121,4 +121,10 @@ public abstract class DelegatingResolvedCall<D extends CallableDescriptor> imple
|
||||
public boolean isSafeCall() {
|
||||
return resolvedCall.isSafeCall();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KotlinType getSmartCastDispatchReceiverType() {
|
||||
return resolvedCall.getSmartCastDispatchReceiverType();
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.resolve.DelegatingBindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystem;
|
||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||
|
||||
public interface MutableResolvedCall<D extends CallableDescriptor> extends ResolvedCall<D> {
|
||||
@@ -64,4 +65,6 @@ public interface MutableResolvedCall<D extends CallableDescriptor> extends Resol
|
||||
|
||||
//todo remove: use value to parameter map status
|
||||
boolean hasInferredReturnType();
|
||||
|
||||
void setSmartCastDispatchReceiverType(@NotNull KotlinType smartCastDispatchReceiverType);
|
||||
}
|
||||
|
||||
@@ -85,4 +85,7 @@ public interface ResolvedCall<D extends CallableDescriptor> {
|
||||
DataFlowInfoForArguments getDataFlowInfoForArguments();
|
||||
|
||||
boolean isSafeCall();
|
||||
|
||||
@Nullable
|
||||
KotlinType getSmartCastDispatchReceiverType();
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableRe
|
||||
private ConstraintSystem constraintSystem = null;
|
||||
private Boolean hasInferredReturnType = null;
|
||||
private boolean completed = false;
|
||||
private KotlinType smartCastDispatchReceiverType = null;
|
||||
|
||||
private ResolvedCallImpl(
|
||||
@NotNull ResolutionCandidate<D> candidate,
|
||||
@@ -370,4 +371,15 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableRe
|
||||
public TypeSubstitutor getKnownTypeParametersSubstitutor() {
|
||||
return knownTypeParametersSubstitutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSmartCastDispatchReceiverType(@NotNull KotlinType smartCastDispatchReceiverType) {
|
||||
this.smartCastDispatchReceiverType = smartCastDispatchReceiverType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public KotlinType getSmartCastDispatchReceiverType() {
|
||||
return smartCastDispatchReceiverType;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user