[FIR] Fix false-positive smartcast on receiver in rhs of elvis
#KT-44942 Fixed
This commit is contained in:
+6
@@ -37452,6 +37452,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44932.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt44942.kt")
|
||||
public void testKt44942() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaArgumentWithoutType.kt")
|
||||
public void testLambdaArgumentWithoutType() throws Exception {
|
||||
|
||||
+8
-6
@@ -1136,12 +1136,6 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
|
||||
lhsExitNode.mergeIncomingFlow()
|
||||
val flow = lhsExitNode.flow
|
||||
val lhsVariable = variableStorage.getOrCreateVariable(flow, elvisExpression.lhs)
|
||||
rhsEnterNode.flow = logicSystem.approveStatementsInsideFlow(
|
||||
flow,
|
||||
lhsVariable eq null,
|
||||
shouldForkFlow = true,
|
||||
shouldRemoveSynthetics = false
|
||||
)
|
||||
lhsIsNotNullNode.flow = logicSystem.approveStatementsInsideFlow(
|
||||
flow,
|
||||
lhsVariable notEq null,
|
||||
@@ -1152,6 +1146,14 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
|
||||
it.addTypeStatement(lhsVariable typeEq any)
|
||||
}
|
||||
}
|
||||
rhsEnterNode.flow = logicSystem.approveStatementsInsideFlow(
|
||||
flow,
|
||||
lhsVariable eq null,
|
||||
shouldForkFlow = true,
|
||||
shouldRemoveSynthetics = false
|
||||
).also {
|
||||
logicSystem.updateAllReceivers(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun exitElvis(elvisExpression: FirElvisExpression) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// ISSUE: KT-44942
|
||||
|
||||
abstract class A {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo(): String = "fail"
|
||||
|
||||
fun bar() = "fail"
|
||||
}
|
||||
|
||||
class C : A() {
|
||||
override fun foo(): String = "OK"
|
||||
}
|
||||
|
||||
fun A.test() = (this as? B)?.bar() ?: foo()
|
||||
|
||||
fun box() = C().test()
|
||||
+6
@@ -37452,6 +37452,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44932.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt44942.kt")
|
||||
public void testKt44942() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaArgumentWithoutType.kt")
|
||||
public void testLambdaArgumentWithoutType() throws Exception {
|
||||
|
||||
+6
@@ -37452,6 +37452,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44932.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt44942.kt")
|
||||
public void testKt44942() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaArgumentWithoutType.kt")
|
||||
public void testLambdaArgumentWithoutType() throws Exception {
|
||||
|
||||
+5
@@ -29926,6 +29926,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44932.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt44942.kt")
|
||||
public void testKt44942() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaArgumentWithoutType.kt")
|
||||
public void testLambdaArgumentWithoutType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/lambdaArgumentWithoutType.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -25537,6 +25537,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44932.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt44942.kt")
|
||||
public void testKt44942() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaArgumentWithoutType.kt")
|
||||
public void testLambdaArgumentWithoutType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/lambdaArgumentWithoutType.kt");
|
||||
|
||||
Generated
+5
@@ -25022,6 +25022,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44932.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt44942.kt")
|
||||
public void testKt44942() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaArgumentWithoutType.kt")
|
||||
public void testLambdaArgumentWithoutType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/lambdaArgumentWithoutType.kt");
|
||||
|
||||
Generated
+5
@@ -24982,6 +24982,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44932.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt44942.kt")
|
||||
public void testKt44942() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaArgumentWithoutType.kt")
|
||||
public void testLambdaArgumentWithoutType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/lambdaArgumentWithoutType.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -13599,6 +13599,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44932.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt44942.kt")
|
||||
public void testKt44942() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/kt44942.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multipleSmartCast.kt")
|
||||
public void testMultipleSmartCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/multipleSmartCast.kt");
|
||||
|
||||
Reference in New Issue
Block a user