diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index d743d1a9b93..71e52bb0fb4 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -20445,6 +20445,21 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/smartCasts/kt3224.kt"); } + @TestMetadata("kt32358_1.kt") + public void testKt32358_1() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt32358_1.kt"); + } + + @TestMetadata("kt32358_2.kt") + public void testKt32358_2() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt32358_2.kt"); + } + + @TestMetadata("kt32358_3.kt") + public void testKt32358_3() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt32358_3.kt"); + } + @TestMetadata("kt3244.kt") public void testKt3244() throws Exception { runTest("compiler/testData/diagnostics/tests/smartCasts/kt3244.kt"); diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt32358_1.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt32358_1.fir.kt new file mode 100644 index 00000000000..1d8c2ac98ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt32358_1.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +NewInference + +class MyChild { + val nullableString: String? = null + val notNull = "" +} + +class MyParent { + val child: MyChild? = MyChild() +} + +fun myFun() { + val myParent = MyParent() + myParent.child?.nullableString ?: run { return } + + myParent.child.notNull // <- No smart cast in plugin +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt32358_1.kt b/compiler/testData/diagnostics/tests/smartCasts/kt32358_1.kt new file mode 100644 index 00000000000..55b270b0a30 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt32358_1.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +NewInference + +class MyChild { + val nullableString: String? = null + val notNull = "" +} + +class MyParent { + val child: MyChild? = MyChild() +} + +fun myFun() { + val myParent = MyParent() + myParent.child?.nullableString ?: run { return } + + myParent.child.notNull // <- No smart cast in plugin +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt32358_1.txt b/compiler/testData/diagnostics/tests/smartCasts/kt32358_1.txt new file mode 100644 index 00000000000..3988e62ca91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt32358_1.txt @@ -0,0 +1,20 @@ +package + +public fun myFun(): kotlin.Unit + +public final class MyChild { + public constructor MyChild() + public final val notNull: kotlin.String = "" + public final val nullableString: kotlin.String? = null + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class MyParent { + public constructor MyParent() + public final val child: MyChild? + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt32358_2.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt32358_2.fir.kt new file mode 100644 index 00000000000..84e4116f5b9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt32358_2.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE_ERROR -UNUSED_PARAMETER + +import kotlin.contracts.* + +inline fun callIt(fn: () -> R): R = TODO() + +inline fun callItContracted(fn: () -> R): R { + contract { + callsInPlace(fn, InvocationKind.EXACTLY_ONCE) + } + TODO() +} + +fun smartIt(p1: String?, p2: String?) { + p1 ?: callIt { return } + p1.length + + p2 ?: callItContracted { return } + p2.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt32358_2.kt b/compiler/testData/diagnostics/tests/smartCasts/kt32358_2.kt new file mode 100644 index 00000000000..d05d0c98b10 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt32358_2.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE_ERROR -UNUSED_PARAMETER + +import kotlin.contracts.* + +inline fun callIt(fn: () -> R): R = TODO() + +inline fun callItContracted(fn: () -> R): R { + contract { + callsInPlace(fn, InvocationKind.EXACTLY_ONCE) + } + TODO() +} + +fun smartIt(p1: String?, p2: String?) { + p1 ?: callIt { return } + p1.length + + p2 ?: callItContracted { return } + p2.length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt32358_2.txt b/compiler/testData/diagnostics/tests/smartCasts/kt32358_2.txt new file mode 100644 index 00000000000..a50c96468e5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt32358_2.txt @@ -0,0 +1,7 @@ +package + +public inline fun callIt(/*0*/ fn: () -> R): R +public inline fun callItContracted(/*0*/ fn: () -> R): R + CallsInPlace(fn, EXACTLY_ONCE) + +public fun smartIt(/*0*/ p1: kotlin.String?, /*1*/ p2: kotlin.String?): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt32358_3.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/kt32358_3.fir.kt new file mode 100644 index 00000000000..11e7a95bddf --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt32358_3.fir.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// no inline modifier +fun callIt(fn: () -> R): R = TODO() + +fun smartIt(p1: String?, p2: String?) { + p1 ?: callIt { TODO() } + p1.length // smartcast +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt32358_3.kt b/compiler/testData/diagnostics/tests/smartCasts/kt32358_3.kt new file mode 100644 index 00000000000..398798835b5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt32358_3.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// no inline modifier +fun callIt(fn: () -> R): R = TODO() + +fun smartIt(p1: String?, p2: String?) { + p1 ?: callIt { TODO() } + p1.length // smartcast +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt32358_3.txt b/compiler/testData/diagnostics/tests/smartCasts/kt32358_3.txt new file mode 100644 index 00000000000..0e95d9ee576 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt32358_3.txt @@ -0,0 +1,4 @@ +package + +public fun callIt(/*0*/ fn: () -> R): R +public fun smartIt(/*0*/ p1: kotlin.String?, /*1*/ p2: kotlin.String?): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index f8fc3639a16..4512bf0c024 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -20522,6 +20522,21 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/smartCasts/kt3224.kt"); } + @TestMetadata("kt32358_1.kt") + public void testKt32358_1() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt32358_1.kt"); + } + + @TestMetadata("kt32358_2.kt") + public void testKt32358_2() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt32358_2.kt"); + } + + @TestMetadata("kt32358_3.kt") + public void testKt32358_3() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt32358_3.kt"); + } + @TestMetadata("kt3244.kt") public void testKt3244() throws Exception { runTest("compiler/testData/diagnostics/tests/smartCasts/kt3244.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 1393ac3e654..2dbc4d0f3a3 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -20447,6 +20447,21 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/smartCasts/kt3224.kt"); } + @TestMetadata("kt32358_1.kt") + public void testKt32358_1() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt32358_1.kt"); + } + + @TestMetadata("kt32358_2.kt") + public void testKt32358_2() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt32358_2.kt"); + } + + @TestMetadata("kt32358_3.kt") + public void testKt32358_3() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/kt32358_3.kt"); + } + @TestMetadata("kt3244.kt") public void testKt3244() throws Exception { runTest("compiler/testData/diagnostics/tests/smartCasts/kt3244.kt");