use smart cast info while adding constraint for receiver
This commit is contained in:
@@ -640,6 +640,10 @@ public class CandidateResolver {
|
|||||||
context.candidateCall.isSafeCall()
|
context.candidateCall.isSafeCall()
|
||||||
? TypeUtils.makeNotNullable(receiverArgument.getType())
|
? TypeUtils.makeNotNullable(receiverArgument.getType())
|
||||||
: receiverArgument.getType();
|
: receiverArgument.getType();
|
||||||
|
if (receiverArgument instanceof ExpressionReceiver) {
|
||||||
|
receiverType = updateResultTypeForSmartCasts(receiverType, ((ExpressionReceiver) receiverArgument).getExpression(),
|
||||||
|
context.dataFlowInfo, context.trace);
|
||||||
|
}
|
||||||
constraintSystem.addSubtypeConstraint(receiverType, receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION);
|
constraintSystem.addSubtypeConstraint(receiverType, receiverParameter.getType(), ConstraintPosition.RECEIVER_POSITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
trait A
|
||||||
|
trait B
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
fun test(a: A?, b: B, list: MutableList<Pair<A, B>>) {
|
||||||
|
if (a != null) {
|
||||||
|
list.add(<!DEBUG_INFO_AUTOCAST!>a<!> to b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Pair<out A, out B>(val first: A, val second: B)
|
||||||
|
fun <A, B> A.to(that: B) = Pair(this, that)
|
||||||
@@ -6299,6 +6299,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest("compiler/testData/diagnostics/tests/smartCasts/inference/kt4009.kt");
|
doTest("compiler/testData/diagnostics/tests/smartCasts/inference/kt4009.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("smartCastOnReceiver.kt")
|
||||||
|
public void testSmartCastOnReceiver() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/smartCasts/inference/smartCastOnReceiver.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test innerSuite() {
|
public static Test innerSuite() {
|
||||||
|
|||||||
Reference in New Issue
Block a user