[FIR] Fix detecting that if in then branch of outer if used as expression
This commit is contained in:
committed by
TeamCityServer
parent
e6588ee8a4
commit
671ebc6819
+5
@@ -1333,6 +1333,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt");
|
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")
|
@TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt")
|
||||||
public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception {
|
public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception {
|
||||||
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/nonExhaustiveWhenWithCoercionToUnit.kt");
|
||||||
|
|||||||
Vendored
+20
@@ -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|(<L> = run@fun <anonymous>(): R|kotlin/Unit| {
|
||||||
|
when () {
|
||||||
|
R|<local>/b1| -> {
|
||||||
|
when () {
|
||||||
|
R|<local>/b2| -> {
|
||||||
|
R|<local>/result| = Boolean(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
fun run(block: () -> Unit) {}
|
||||||
|
|
||||||
|
fun test(b1: Boolean, b2: Boolean) {
|
||||||
|
var result = false
|
||||||
|
run {
|
||||||
|
if (b1)
|
||||||
|
if (b2)
|
||||||
|
result = true
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -1524,6 +1524,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt");
|
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
|
@Test
|
||||||
@TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt")
|
@TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt")
|
||||||
public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception {
|
public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception {
|
||||||
|
|||||||
+6
@@ -1539,6 +1539,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/exhaustiveness_sealedSubClass.kt");
|
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
|
@Test
|
||||||
@TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt")
|
@TestMetadata("nonExhaustiveWhenWithCoercionToUnit.kt")
|
||||||
public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception {
|
public void testNonExhaustiveWhenWithCoercionToUnit() throws Exception {
|
||||||
|
|||||||
+1
-1
@@ -1111,7 +1111,7 @@ class ExpressionsConverter(
|
|||||||
}
|
}
|
||||||
val parentTokenType = parent.tokenType
|
val parentTokenType = parent.tokenType
|
||||||
if (parentTokenType == BLOCK) return false
|
if (parentTokenType == BLOCK) return false
|
||||||
if (parentTokenType == ELSE || parentTokenType == WHEN_ENTRY) {
|
if (parentTokenType == THEN || parentTokenType == ELSE || parentTokenType == WHEN_ENTRY) {
|
||||||
return parent.getParent()?.usedAsExpression ?: true
|
return parent.getParent()?.usedAsExpression ?: true
|
||||||
}
|
}
|
||||||
if (parentTokenType != BODY) return true
|
if (parentTokenType != BODY) return true
|
||||||
|
|||||||
@@ -1631,7 +1631,7 @@ class RawFirBuilder(
|
|||||||
}
|
}
|
||||||
if (parent is KtBlockExpression) return false
|
if (parent is KtBlockExpression) return false
|
||||||
when (parent.elementType) {
|
when (parent.elementType) {
|
||||||
KtNodeTypes.ELSE, KtNodeTypes.WHEN_ENTRY -> {
|
KtNodeTypes.THEN, KtNodeTypes.ELSE, KtNodeTypes.WHEN_ENTRY -> {
|
||||||
return (parent.parent as? KtExpression)?.usedAsExpression ?: true
|
return (parent.parent as? KtExpression)?.usedAsExpression ?: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user