FIR. Fix smart-cast expression unwrapping in plus with assign resolve

This commit is contained in:
Simon Ogorodnik
2022-08-20 09:18:50 +02:00
committed by teamcity
parent f946496979
commit 8f51c51eee
7 changed files with 58 additions and 1 deletions
@@ -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 {
@@ -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");
@@ -0,0 +1,23 @@
FILE: plusWithAssignSmartCast.kt
public final class Foo : R|kotlin/Any| {
public constructor(): R|Foo| {
super<R|kotlin/Any|>()
}
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|<local>/other|
}
else -> {
this@R|/Foo|.R|/Foo.bar| = this@R|/Foo|.R|/Foo.bar|.R|kotlin/plus|(<strcat>(String( ), R|<local>/other|))
}
}
}
}
@@ -0,0 +1,11 @@
class Foo {
var bar: String? = null
fun addToBar(other: String) {
if (bar == null) {
bar = other
} else {
bar += " $other"
}
}
}
@@ -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 {
@@ -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 {
@@ -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)