From ab1d27dd6bd4196178806a4cdbdabbce5c8d1428 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Tue, 3 Dec 2013 14:26:18 +0400 Subject: [PATCH] don't use data flow info while checking for receiver receiver with smart cast is checked separately --- .../jet/lang/resolve/calls/CandidateResolver.java | 3 +-- .../testData/diagnostics/tests/smartCasts/publicVal.kt | 10 ++++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/publicVal.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 505d969555a..8abd8d2334c 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 @@ -891,8 +891,7 @@ public class CandidateResolver { BindingContext bindingContext = trace.getBindingContext(); boolean safeAccess = isExplicitReceiver && !implicitInvokeCheck && candidateCall.isSafeCall(); - AutoCastServiceImpl autoCastService = new AutoCastServiceImpl(context.dataFlowInfo, bindingContext); - if (!safeAccess && !receiverParameter.getType().isNullable() && !autoCastService.isNotNull(receiverArgument)) { + if (!safeAccess && !receiverParameter.getType().isNullable() && receiverArgument.getType().isNullable()) { context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck); return UNSAFE_CALL_ERROR; diff --git a/compiler/testData/diagnostics/tests/smartCasts/publicVal.kt b/compiler/testData/diagnostics/tests/smartCasts/publicVal.kt new file mode 100644 index 00000000000..fd7f2e7c417 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/publicVal.kt @@ -0,0 +1,10 @@ +public class A() { + public val foo: Int? = 1 +} + +fun Int.bar(i: Int) = i + +fun test() { + val p = A() + if (p.foo is Int) p.foo bar 11 +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index c7fb6f2cf8f..fe38410a9ca 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -6178,6 +6178,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/smartCasts/noUnnecessarySmartCastForReceiver.kt"); } + @TestMetadata("publicVal.kt") + public void testPublicVal() throws Exception { + doTest("compiler/testData/diagnostics/tests/smartCasts/publicVal.kt"); + } + @TestMetadata("thisWithLabel.kt") public void testThisWithLabel() throws Exception { doTest("compiler/testData/diagnostics/tests/smartCasts/thisWithLabel.kt");