diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 60503ce7e00..8982f076273 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -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 { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt index 260f375901e..5960fc3ca1a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt @@ -1136,12 +1136,6 @@ abstract class FirDataFlowAnalyzer( 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( 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) { diff --git a/compiler/testData/codegen/box/smartCasts/kt44942.kt b/compiler/testData/codegen/box/smartCasts/kt44942.kt new file mode 100644 index 00000000000..9289788a54d --- /dev/null +++ b/compiler/testData/codegen/box/smartCasts/kt44942.kt @@ -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() diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 291a14d1ad9..32dfc2c6864 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -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 { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index f5ffd7be0e1..11c8ae6dd32 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -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 { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 0125295a2e4..3163f01223c 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -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"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index a2c682d5817..ce88f8a2ccd 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -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"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 8e9184a794f..421555239ab 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -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"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 49d053060d1..4c83fd5c74c 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -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"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 278e24bee54..ed5098f8259 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -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");