From b8447d6d97947922fab3a9193a0d47a54c913742 Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Mon, 20 Nov 2017 18:00:32 +0300 Subject: [PATCH] Add test on smartcasts with reified types This test introduces very special (for current implementation) case, when we have smartcast indirectly, via some reified type parameter. It covers recursive call inSmartCastManager.checkAndRecordPossibleCast(), which wasn't previously covered by any test in testbase. --- .../tests/smartCasts/severalSmartCastsOnReified.kt | 11 +++++++++++ .../tests/smartCasts/severalSmartCastsOnReified.txt | 4 ++++ .../kotlin/checkers/DiagnosticsTestGenerated.java | 6 ++++++ .../javac/DiagnosticsUsingJavacTestGenerated.java | 6 ++++++ 4 files changed, 27 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.txt diff --git a/compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.kt b/compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.kt new file mode 100644 index 00000000000..84fe47bbbc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.kt @@ -0,0 +1,11 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +inline fun foo(y: Any?) { + if (y is T?) { + if (y != null) { + bar(y) + } + } +} + +fun bar(x: CharSequence) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.txt b/compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.txt new file mode 100644 index 00000000000..f04d1732288 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.txt @@ -0,0 +1,4 @@ +package + +public fun bar(/*0*/ x: kotlin.CharSequence): kotlin.Unit +public inline fun foo(/*0*/ y: kotlin.Any?): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 4445f3924cf..09a36ea539d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -20818,6 +20818,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("severalSmartCastsOnReified.kt") + public void testSeveralSmartCastsOnReified() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.kt"); + doTest(fileName); + } + @TestMetadata("shortIfExprNotNull.kt") public void testShortIfExprNotNull() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/shortIfExprNotNull.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index ca2db51fae6..d975eb8fa24 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -20818,6 +20818,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing doTest(fileName); } + @TestMetadata("severalSmartCastsOnReified.kt") + public void testSeveralSmartCastsOnReified() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/severalSmartCastsOnReified.kt"); + doTest(fileName); + } + @TestMetadata("shortIfExprNotNull.kt") public void testShortIfExprNotNull() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/shortIfExprNotNull.kt");