dynamic receiver admits nullable values
This commit is contained in:
@@ -597,8 +597,7 @@ public class CandidateResolver {
|
||||
|
||||
BindingContext bindingContext = trace.getBindingContext();
|
||||
if (!safeAccess && !receiverParameter.getType().isNullable() && receiverArgumentType.isNullable()) {
|
||||
if (!SmartCastUtils.isNotNull(receiverArgument, bindingContext, context.dataFlowInfo)) {
|
||||
|
||||
if (!SmartCastUtils.canBeSmartCast(receiverParameter, receiverArgument, bindingContext, context.dataFlowInfo)) {
|
||||
context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck);
|
||||
return UNSAFE_CALL_ERROR;
|
||||
}
|
||||
|
||||
+4
-2
@@ -22,6 +22,7 @@ import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
@@ -183,7 +184,8 @@ public class SmartCastUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isNotNull(
|
||||
public static boolean canBeSmartCast(
|
||||
@NotNull ReceiverParameterDescriptor receiverParameter,
|
||||
@NotNull ReceiverValue receiver,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull DataFlowInfo dataFlowInfo
|
||||
@@ -192,7 +194,7 @@ public class SmartCastUtils {
|
||||
|
||||
List<JetType> smartCastVariants = getSmartCastVariants(receiver, bindingContext, dataFlowInfo);
|
||||
for (JetType smartCastVariant : smartCastVariants) {
|
||||
if (!smartCastVariant.isNullable()) return true;
|
||||
if (JetTypeChecker.DEFAULT.isSubtypeOf(smartCastVariant, receiverParameter.getType())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user