use smart cast info while adding constraint for receiver

This commit is contained in:
Svetlana Isakova
2013-12-19 20:18:14 +04:00
parent b4dbd69d23
commit cfb7bcb73b
3 changed files with 22 additions and 0 deletions
@@ -640,6 +640,10 @@ public class CandidateResolver {
context.candidateCall.isSafeCall()
? TypeUtils.makeNotNullable(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);
}
@@ -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");
}
@TestMetadata("smartCastOnReceiver.kt")
public void testSmartCastOnReceiver() throws Exception {
doTest("compiler/testData/diagnostics/tests/smartCasts/inference/smartCastOnReceiver.kt");
}
}
public static Test innerSuite() {