From cfb7bcb73bc9ca0331240f2bcf138277aca04185 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Thu, 19 Dec 2013 20:18:14 +0400 Subject: [PATCH] use smart cast info while adding constraint for receiver --- .../jet/lang/resolve/calls/CandidateResolver.java | 4 ++++ .../smartCasts/inference/smartCastOnReceiver.kt | 13 +++++++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/inference/smartCastOnReceiver.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java index 140cacfced1..9e3b0d3acbf 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java @@ -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); } diff --git a/compiler/testData/diagnostics/tests/smartCasts/inference/smartCastOnReceiver.kt b/compiler/testData/diagnostics/tests/smartCasts/inference/smartCastOnReceiver.kt new file mode 100644 index 00000000000..6eb7dbc54e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/inference/smartCastOnReceiver.kt @@ -0,0 +1,13 @@ +trait A +trait B + +class Test { + fun test(a: A?, b: B, list: MutableList>) { + if (a != null) { + list.add(a to b) + } + } +} + +class Pair(val first: A, val second: B) +fun A.to(that: B) = Pair(this, that) \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 014d18a6139..64aaef8b6eb 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -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() {