From 6698e0ecc97902d17ecf190cb73c5897c17d2fcd Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 16 Oct 2014 16:35:11 +0400 Subject: [PATCH] Add test for outdated smart cast with elvis issue #KT-5335 Obsolete --- .../smartCasts/{elvis.kt => elvisNothingRHS.kt} | 2 +- .../smartCasts/{elvis.txt => elvisNothingRHS.txt} | 0 .../diagnostics/tests/smartCasts/elvisRHS.kt | 10 ++++++++++ .../diagnostics/tests/smartCasts/elvisRHS.txt | 3 +++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 12 +++++++++--- .../org/jetbrains/jet/j2k/ConstructorConverter.kt | 2 +- 6 files changed, 24 insertions(+), 5 deletions(-) rename compiler/testData/diagnostics/tests/smartCasts/{elvis.kt => elvisNothingRHS.kt} (98%) rename compiler/testData/diagnostics/tests/smartCasts/{elvis.txt => elvisNothingRHS.txt} (100%) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/elvisRHS.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/elvisRHS.txt diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvis.kt b/compiler/testData/diagnostics/tests/smartCasts/elvisNothingRHS.kt similarity index 98% rename from compiler/testData/diagnostics/tests/smartCasts/elvis.kt rename to compiler/testData/diagnostics/tests/smartCasts/elvisNothingRHS.kt index f2f3dd4083a..c88f924b79d 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/elvis.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/elvisNothingRHS.kt @@ -8,4 +8,4 @@ fun test(a: C?, nn: () -> Nothing?) { a ?: return a.foo() -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvis.txt b/compiler/testData/diagnostics/tests/smartCasts/elvisNothingRHS.txt similarity index 100% rename from compiler/testData/diagnostics/tests/smartCasts/elvis.txt rename to compiler/testData/diagnostics/tests/smartCasts/elvisNothingRHS.txt diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvisRHS.kt b/compiler/testData/diagnostics/tests/smartCasts/elvisRHS.kt new file mode 100644 index 00000000000..f886778d875 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvisRHS.kt @@ -0,0 +1,10 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +// KT-5335 + +fun foo(p1: String?, p2: String?) { + if (p2 != null) { + val v = p1 ?: p2 + val size = v.length + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/elvisRHS.txt b/compiler/testData/diagnostics/tests/smartCasts/elvisRHS.txt new file mode 100644 index 00000000000..b2e8d641bc5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/elvisRHS.txt @@ -0,0 +1,3 @@ +package + +internal fun foo(/*0*/ p1: kotlin.String?, /*1*/ p2: kotlin.String?): kotlin.Unit \ 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 9dcb31a36c0..537a849be51 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -9356,9 +9356,15 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } - @TestMetadata("elvis.kt") - public void testElvis() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/elvis.kt"); + @TestMetadata("elvisNothingRHS.kt") + public void testElvisNothingRHS() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/elvisNothingRHS.kt"); + doTest(fileName); + } + + @TestMetadata("elvisRHS.kt") + public void testElvisRHS() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/elvisRHS.kt"); doTest(fileName); } diff --git a/j2k/src/org/jetbrains/jet/j2k/ConstructorConverter.kt b/j2k/src/org/jetbrains/jet/j2k/ConstructorConverter.kt index f8ef89a6b20..9af191b4881 100644 --- a/j2k/src/org/jetbrains/jet/j2k/ConstructorConverter.kt +++ b/j2k/src/org/jetbrains/jet/j2k/ConstructorConverter.kt @@ -84,7 +84,7 @@ class ConstructorConverter(private val psiClass: PsiClass, else null } - val finalTarget = finalTargetInfo?.constructor ?: target!! //TODO: see KT-5335 + val finalTarget = finalTargetInfo?.constructor ?: target toTargetConstructorMap[constructor] = TargetConstructorInfo(finalTarget, parameterDefaults) for (entry in toTargetConstructorMap.entrySet()) {