diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index 18188169e0c..bff43b51d06 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -2117,6 +2117,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis runTest("compiler/fir/analysis-tests/testData/resolve/expresssions/overriddenJavaGetter.kt"); } + @Test + @TestMetadata("plusWithAssignSmartCast.kt") + public void testPlusWithAssignSmartCast() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/expresssions/plusWithAssignSmartCast.kt"); + } + @Test @TestMetadata("privateObjectLiteral.kt") public void testPrivateObjectLiteral() throws Exception { 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 e0c70d352b9..3499abbf556 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 @@ -1846,6 +1846,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract runTest("compiler/fir/analysis-tests/testData/resolve/expresssions/overriddenJavaGetter.kt"); } + @TestMetadata("plusWithAssignSmartCast.kt") + public void testPlusWithAssignSmartCast() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/expresssions/plusWithAssignSmartCast.kt"); + } + @TestMetadata("privateObjectLiteral.kt") public void testPrivateObjectLiteral() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/expresssions/privateObjectLiteral.kt"); diff --git a/compiler/fir/analysis-tests/testData/resolve/expresssions/plusWithAssignSmartCast.fir.txt b/compiler/fir/analysis-tests/testData/resolve/expresssions/plusWithAssignSmartCast.fir.txt new file mode 100644 index 00000000000..6ce8c9c60a7 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/expresssions/plusWithAssignSmartCast.fir.txt @@ -0,0 +1,23 @@ +FILE: plusWithAssignSmartCast.kt + public final class Foo : R|kotlin/Any| { + public constructor(): R|Foo| { + super() + } + + public final var bar: R|kotlin/String?| = Null(null) + public get(): R|kotlin/String?| + public set(value: R|kotlin/String?|): R|kotlin/Unit| + + public final fun addToBar(other: R|kotlin/String|): R|kotlin/Unit| { + when () { + ==(this@R|/Foo|.R|/Foo.bar|, Null(null)) -> { + this@R|/Foo|.R|/Foo.bar| = R|/other| + } + else -> { + this@R|/Foo|.R|/Foo.bar| = this@R|/Foo|.R|/Foo.bar|.R|kotlin/plus|((String( ), R|/other|)) + } + } + + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolve/expresssions/plusWithAssignSmartCast.kt b/compiler/fir/analysis-tests/testData/resolve/expresssions/plusWithAssignSmartCast.kt new file mode 100644 index 00000000000..55a82164812 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/expresssions/plusWithAssignSmartCast.kt @@ -0,0 +1,11 @@ +class Foo { + var bar: String? = null + + fun addToBar(other: String) { + if (bar == null) { + bar = other + } else { + bar += " $other" + } + } +} \ No newline at end of file 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 e701aa9bbb8..106e7dc3161 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 @@ -2117,6 +2117,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { runTest("compiler/fir/analysis-tests/testData/resolve/expresssions/overriddenJavaGetter.kt"); } + @Test + @TestMetadata("plusWithAssignSmartCast.kt") + public void testPlusWithAssignSmartCast() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/expresssions/plusWithAssignSmartCast.kt"); + } + @Test @TestMetadata("privateObjectLiteral.kt") public void testPrivateObjectLiteral() 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 ca46784d138..2119daabae5 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 @@ -2117,6 +2117,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/expresssions/overriddenJavaGetter.kt"); } + @Test + @TestMetadata("plusWithAssignSmartCast.kt") + public void testPlusWithAssignSmartCast() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/expresssions/plusWithAssignSmartCast.kt"); + } + @Test @TestMetadata("privateObjectLiteral.kt") public void testPrivateObjectLiteral() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index 6505d62cca6..f52d65a519c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -605,7 +605,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform } } } - (leftArgument as? FirQualifiedAccess)?.let { + (leftArgument.unwrapSmartcastExpression() as? FirQualifiedAccess)?.let { dispatchReceiver = it.dispatchReceiver extensionReceiver = it.extensionReceiver contextReceiverArguments.addAll(it.contextReceiverArguments)