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 418a7c3a1bf..084912af263 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 @@ -1333,6 +1333,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt"); } + @TestMetadata("nestedIfInLambda.kt") + public void testNestedIfInLambda() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nestedIfInLambda.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/positive/nestedIfInLambda.fir.txt b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nestedIfInLambda.fir.txt new file mode 100644 index 00000000000..468e5d76177 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nestedIfInLambda.fir.txt @@ -0,0 +1,20 @@ +FILE: nestedIfInLambda.kt + public final fun run(block: R|() -> kotlin/Unit|): R|kotlin/Unit| { + } + public final fun test(b1: R|kotlin/Boolean|, b2: R|kotlin/Boolean|): R|kotlin/Unit| { + lvar result: R|kotlin/Boolean| = Boolean(false) + R|/run|( = run@fun (): R|kotlin/Unit| { + when () { + R|/b1| -> { + when () { + R|/b2| -> { + R|/result| = Boolean(true) + } + } + + } + } + + } + ) + } diff --git a/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nestedIfInLambda.kt b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nestedIfInLambda.kt new file mode 100644 index 00000000000..1464b640c70 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nestedIfInLambda.kt @@ -0,0 +1,10 @@ +fun run(block: () -> Unit) {} + +fun test(b1: Boolean, b2: Boolean) { + var result = false + run { + if (b1) + if (b2) + result = true + } +} 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 6bd06b6a5e3..dc995f11a31 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 @@ -1524,6 +1524,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt"); } + @Test + @TestMetadata("nestedIfInLambda.kt") + public void testNestedIfInLambda() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nestedIfInLambda.kt"); + } + @Test @TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt") public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception { 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 223e54c2497..fbdb96cf4b0 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 @@ -1539,6 +1539,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt"); } + @Test + @TestMetadata("nestedIfInLambda.kt") + public void testNestedIfInLambda() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nestedIfInLambda.kt"); + } + @Test @TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt") public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception { diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt index 43a3f9b436e..394b650ec39 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt @@ -1111,7 +1111,7 @@ class ExpressionsConverter( } val parentTokenType = parent.tokenType if (parentTokenType == BLOCK) return false - if (parentTokenType == ELSE || parentTokenType == WHEN_ENTRY) { + if (parentTokenType == THEN || parentTokenType == ELSE || parentTokenType == WHEN_ENTRY) { return parent.getParent()?.usedAsExpression ?: true } if (parentTokenType != BODY) return true diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 834fc288308..e45a001a557 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -1631,7 +1631,7 @@ class RawFirBuilder( } if (parent is KtBlockExpression) return false when (parent.elementType) { - KtNodeTypes.ELSE, KtNodeTypes.WHEN_ENTRY -> { + KtNodeTypes.THEN, KtNodeTypes.ELSE, KtNodeTypes.WHEN_ENTRY -> { return (parent.parent as? KtExpression)?.usedAsExpression ?: true } }