From 46b77f447221280fbf37b15dddb8bbffb7ffc174 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Tue, 3 Dec 2013 14:19:11 +0400 Subject: [PATCH] don't report unnecessary smart cast on receiver --- .../lang/resolve/calls/autocasts/AutoCastServiceImpl.java | 3 ++- .../diagnostics/tests/inference/regressions/kt1358.kt | 4 ++-- compiler/testData/diagnostics/tests/infos/Autocasts.kt | 2 +- .../tests/smartCasts/noUnnecessarySmartCastForReceiver.kt | 7 +++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ idea/testData/checker/infos/Autocasts.kt | 6 +++--- 6 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/noUnnecessarySmartCastForReceiver.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastServiceImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastServiceImpl.java index 88148c2f75f..73ed966dea3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastServiceImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/AutoCastServiceImpl.java @@ -35,8 +35,9 @@ public class AutoCastServiceImpl implements AutoCastService { @NotNull @Override public List getVariantsForReceiver(@NotNull ReceiverValue receiverValue) { - List variants = Lists.newArrayList(AutoCastUtils.getAutoCastVariants(bindingContext, dataFlowInfo, receiverValue)); + List variants = Lists.newArrayList(); variants.add(receiverValue); + variants.addAll(AutoCastUtils.getAutoCastVariants(bindingContext, dataFlowInfo, receiverValue)); return variants; } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1358.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1358.kt index afe85753944..5c28166bb42 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt1358.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1358.kt @@ -3,8 +3,8 @@ package d fun bar(a: Any?) { if (a != null) { - a.foo() //overload resolution ambiguity - a.sure() //overload resolution ambiguity + a.foo() //overload resolution ambiguity + a.sure() //overload resolution ambiguity } } diff --git a/compiler/testData/diagnostics/tests/infos/Autocasts.kt b/compiler/testData/diagnostics/tests/infos/Autocasts.kt index b661293e910..ce0904651c2 100644 --- a/compiler/testData/diagnostics/tests/infos/Autocasts.kt +++ b/compiler/testData/diagnostics/tests/infos/Autocasts.kt @@ -183,7 +183,7 @@ fun returnFunctionLiteral(a: Any?): Function0 = fun mergeAutocasts(a: Any?) { if (a is String || a is Int) { a.compareTo("") - a.toString() + a.toString() } if (a is Int || a is String) { a.compareTo("") diff --git a/compiler/testData/diagnostics/tests/smartCasts/noUnnecessarySmartCastForReceiver.kt b/compiler/testData/diagnostics/tests/smartCasts/noUnnecessarySmartCastForReceiver.kt new file mode 100644 index 00000000000..9a38cbf1172 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/noUnnecessarySmartCastForReceiver.kt @@ -0,0 +1,7 @@ +fun Any?.foo() {} + +fun test(a: Any?) { + if (a != null) { + a.foo() + } +} \ 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 35fefff94e3..c7fb6f2cf8f 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -6173,6 +6173,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.kt"); } + @TestMetadata("noUnnecessarySmartCastForReceiver.kt") + public void testNoUnnecessarySmartCastForReceiver() throws Exception { + doTest("compiler/testData/diagnostics/tests/smartCasts/noUnnecessarySmartCastForReceiver.kt"); + } + @TestMetadata("thisWithLabel.kt") public void testThisWithLabel() throws Exception { doTest("compiler/testData/diagnostics/tests/smartCasts/thisWithLabel.kt"); diff --git a/idea/testData/checker/infos/Autocasts.kt b/idea/testData/checker/infos/Autocasts.kt index c40a3aeb669..e6bbb1ef9c8 100644 --- a/idea/testData/checker/infos/Autocasts.kt +++ b/idea/testData/checker/infos/Autocasts.kt @@ -165,11 +165,11 @@ fun declarations(a: Any?) { fun vars(a: Any?) { var b: Int = 0 if (a is Int) { - b = a + b = a } } fun returnFunctionLiteralBlock(a: Any?): Function0 { - if (a is Int) return { a } + if (a is Int) return { a } else return { 1 } } fun returnFunctionLiteral(a: Any?): Function0 = @@ -179,7 +179,7 @@ fun returnFunctionLiteral(a: Any?): Function0 = fun mergeAutocasts(a: Any?) { if (a is String || a is Int) { a.compareTo("") - a.toString() + a.toString() } if (a is Int || a is String) { a.compareTo("")