diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/kt10240.kt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/kt10240.kt new file mode 100644 index 00000000000..afaf177ac05 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/kt10240.kt @@ -0,0 +1,36 @@ +fun a(): Int { + fun b(): Int { + var c: Int? = null + if (c == null || + 0 < c // FE 1.0: smart cast impossible, see KT-10240 + ) c = 0 + return c ?: 0 + } + + var c: Int = 0 + c = 0 + return c +} + +fun myRun(f: () -> Unit) { + f() +} + +fun println(arg: Int) {} + +fun d() { + myRun { + var koko: String? = "Alpha" + while (koko != null) { + println(koko.length) + koko = null + } + } + myRun { + var koko: String? = "Omega" + while (koko != null) { + println(koko.length) // FE 1.0: smart cast impossible, see KT-19446 + koko = null + } + } +} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/kt10240.txt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/kt10240.txt new file mode 100644 index 00000000000..ecdf1185447 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/kt10240.txt @@ -0,0 +1,42 @@ +FILE: kt10240.kt + public final fun a(): R|kotlin/Int| { + local final fun b(): R|kotlin/Int| { + lvar c: R|kotlin/Int?| = Null(null) + when () { + ==(R|/c|, Null(null)) || CMP(<, Int(0).R|kotlin/Int.compareTo|(R|/c|)) -> { + R|/c| = Int(0) + } + } + + ^b R|/c| ?: Int(0) + } + + lvar c: R|kotlin/Int| = Int(0) + R|/c| = Int(0) + ^a R|/c| + } + public final fun myRun(f: R|() -> kotlin/Unit|): R|kotlin/Unit| { + R|/f|.R|FakeOverride|() + } + public final fun println(arg: R|kotlin/Int|): R|kotlin/Unit| { + } + public final fun d(): R|kotlin/Unit| { + R|/myRun|( = myRun@fun (): R|kotlin/Unit| { + lvar koko: R|kotlin/String?| = String(Alpha) + while(!=(R|/koko|, Null(null))) { + R|/println|(R|/koko|.R|kotlin/String.length|) + R|/koko| = Null(null) + } + + } + ) + R|/myRun|( = myRun@fun (): R|kotlin/Unit| { + lvar koko: R|kotlin/String?| = String(Omega) + while(!=(R|/koko|, Null(null))) { + R|/println|(R|/koko|.R|kotlin/String.length|) + R|/koko| = Null(null) + } + + } + ) + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 8b44fb18910..f27a0c6195d 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -2259,6 +2259,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/equalsAndIdentity.kt"); } + @TestMetadata("kt10240.kt") + public void testKt10240() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/kt10240.kt"); + } + @TestMetadata("kt37327.kt") public void testKt37327() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/kt37327.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index d0232441e28..85ff23a849a 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -2259,6 +2259,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/equalsAndIdentity.kt"); } + @TestMetadata("kt10240.kt") + public void testKt10240() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/kt10240.kt"); + } + @TestMetadata("kt37327.kt") public void testKt37327() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/kt37327.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java index 1aed7329553..77229a68ec6 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java @@ -2259,6 +2259,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/equalsAndIdentity.kt"); } + @TestMetadata("kt10240.kt") + public void testKt10240() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/kt10240.kt"); + } + @TestMetadata("kt37327.kt") public void testKt37327() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/kt37327.kt");