diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 036af151e02..7d0d4cc6ccf 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -27932,6 +27932,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.kt"); } + @Test + @TestMetadata("implicitThisOnRefInLambdaInSmartcast.kt") + public void testImplicitThisOnRefInLambdaInSmartcast() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt"); + } + @Test @TestMetadata("implicitToGrandSon.kt") public void testImplicitToGrandSon() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index ac18fcf4d0f..72889f3eedb 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -27932,6 +27932,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.kt"); } + @Test + @TestMetadata("implicitThisOnRefInLambdaInSmartcast.kt") + public void testImplicitThisOnRefInLambdaInSmartcast() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt"); + } + @Test @TestMetadata("implicitToGrandSon.kt") public void testImplicitToGrandSon() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index a1544e10a80..0e7b4ca645c 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -27932,6 +27932,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.kt"); } + @Test + @TestMetadata("implicitThisOnRefInLambdaInSmartcast.kt") + public void testImplicitThisOnRefInLambdaInSmartcast() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt"); + } + @Test @TestMetadata("implicitToGrandSon.kt") public void testImplicitToGrandSon() 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 17f564865d0..fb09a0327bf 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 @@ -105,14 +105,15 @@ abstract class FirDataFlowAnalyzer( val index = receiverStack.getReceiverIndex(symbol) ?: return val info = flow.getTypeStatement(variable) - if (info == null) { - receiverStack.replaceReceiverType(index, receiverStack.getOriginalType(index)) + val type = if (info == null) { + receiverStack.getOriginalType(index) } else { val types = info.exactType.toMutableList().also { it += receiverStack.getOriginalType(index) } - receiverStack.replaceReceiverType(index, context.intersectTypesOrNull(types)!!) + context.intersectTypesOrNull(types)!! } + receiverStack.replaceReceiverType(index, type) } override fun updateAllReceivers(flow: PersistentFlow) { @@ -282,6 +283,7 @@ abstract class FirDataFlowAnalyzer( // TODO: questionable postponedLambdaEnterNode?.mergeIncomingFlow() functionEnterNode.mergeIncomingFlow() + logicSystem.updateAllReceivers(functionEnterNode.flow) } private fun exitAnonymousFunction(anonymousFunction: FirAnonymousFunction): FirControlFlowGraphReference { diff --git a/compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.fir.kt new file mode 100644 index 00000000000..fff5a9bf163 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.fir.kt @@ -0,0 +1,7 @@ +fun Any.test() { + val x: () -> Int = when (this) { + is String -> { { length } } + else -> { { 1 } } + } + length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt new file mode 100644 index 00000000000..1b381b72099 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt @@ -0,0 +1,7 @@ +fun Any.test() { + val x: () -> Int = when (this) { + is String -> { { length } } + else -> { { 1 } } + } + length +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.txt b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.txt new file mode 100644 index 00000000000..6ccf3283d3a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.txt @@ -0,0 +1,3 @@ +package + +public fun kotlin.Any.test(): kotlin.Unit diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 9ea4397bcaf..4be2442c3fc 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -28022,6 +28022,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.kt"); } + @Test + @TestMetadata("implicitThisOnRefInLambdaInSmartcast.kt") + public void testImplicitThisOnRefInLambdaInSmartcast() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt"); + } + @Test @TestMetadata("implicitToGrandSon.kt") public void testImplicitToGrandSon() throws Exception {