diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java index ae7e3528124..418a7c3a1bf 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java +++ b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java @@ -1274,6 +1274,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract public void testMissingSealedInheritor() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/missingSealedInheritor.kt"); } + + @TestMetadata("nonExhaustiveWhenWithoutCoercionToUnit.kt") + public void testNonExhaustiveWhenWithoutCoercionToUnit() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.kt"); + } } @TestMetadata("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive") @@ -1327,6 +1332,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract public void testExhaustiveness_sealedSubClass() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt"); } + + @TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt") + public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.kt"); + } } } diff --git a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.fir.txt b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.fir.txt new file mode 100644 index 00000000000..3dbef094d39 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.fir.txt @@ -0,0 +1,15 @@ +FILE: nonExhaustiveWhenWithoutCoercionToUnit.kt + public final fun run(block: R|() -> T|): R|T| { + ^run R|/block|.R|SubstitutionOverride|() + } + public final fun test(a: R|kotlin/Any|): R|kotlin/Unit| { + R|/run|( = run@fun (): R|kotlin/Unit| { + when (R|/a|) { + ($subj$ is R|kotlin/String|) -> { + Int(1) + } + } + + } + ) + } diff --git a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.kt b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.kt new file mode 100644 index 00000000000..35d276b48ea --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.kt @@ -0,0 +1,10 @@ +fun run(block: () -> T): T = block() + +fun test(a: Any) { + run { + // Should be an error, see KT-44810 + when (a) { + is String -> 1 + } + } +} diff --git a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.fir.txt b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.fir.txt new file mode 100644 index 00000000000..3c426b78f6e --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.fir.txt @@ -0,0 +1,21 @@ +FILE: nonExhaustiveWhenWithCoercionToUnit.kt + public final fun run(block: R|() -> T|): R|T| { + ^run R|/block|.R|SubstitutionOverride|() + } + public final fun test(a: R|kotlin/Any|, b: R|kotlin/Boolean|): R|kotlin/Unit| { + R|/run|( = run@fun (): R|kotlin/Unit| { + when () { + R|/b| -> { + ^@run Unit + } + } + + when (R|/a|) { + ($subj$ is R|kotlin/String|) -> { + Int(1) + } + } + + } + ) + } diff --git a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.kt b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.kt new file mode 100644 index 00000000000..4e30a814d3c --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.kt @@ -0,0 +1,10 @@ +fun run(block: () -> T): T = block() + +fun test(a: Any, b: Boolean) { + run { + if (b) return@run + when (a) { + is String -> 1 + } + } +} diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index f7da3ebcfff..6bd06b6a5e3 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -1459,6 +1459,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { public void testMissingSealedInheritor() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/missingSealedInheritor.kt"); } + + @Test + @TestMetadata("nonExhaustiveWhenWithoutCoercionToUnit.kt") + public void testNonExhaustiveWhenWithoutCoercionToUnit() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.kt"); + } } @Nested @@ -1517,6 +1523,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { public void testExhaustiveness_sealedSubClass() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt"); } + + @Test + @TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt") + public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.kt"); + } } } diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index ea8708480aa..223e54c2497 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -1473,6 +1473,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos public void testMissingSealedInheritor() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/missingSealedInheritor.kt"); } + + @Test + @TestMetadata("nonExhaustiveWhenWithoutCoercionToUnit.kt") + public void testNonExhaustiveWhenWithoutCoercionToUnit() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/nonExhaustiveWhenWithoutCoercionToUnit.kt"); + } } @Nested @@ -1532,6 +1538,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos public void testExhaustiveness_sealedSubClass() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt"); } + + @Test + @TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt") + public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.kt"); + } } }