[JVM_IR] Fix check for inline class property backing in lowering.

The inline class lowering would attempt to lower a companion object
property backing field.

^KT-47762 Fixed.
This commit is contained in:
Mads Ager
2021-07-19 12:50:08 +02:00
committed by Alexander Udalov
parent 46d2e52543
commit 2877f1cabe
10 changed files with 58 additions and 1 deletions
@@ -18910,6 +18910,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/inlineClasses/kt47609.kt");
}
@Test
@TestMetadata("kt47762.kt")
public void testKt47762() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47762.kt");
}
@Test
@TestMetadata("mangledDefaultParameterFunction.kt")
public void testMangledDefaultParameterFunction() throws Exception {
@@ -424,7 +424,10 @@ private class JvmInlineClassLowering(private val context: JvmBackendContext) : F
override fun visitGetField(expression: IrGetField): IrExpression {
val field = expression.symbol.owner
val parent = field.parent
if (parent is IrClass && parent.isInline && field.name == parent.inlineClassFieldName) {
if (field.origin == IrDeclarationOrigin.PROPERTY_BACKING_FIELD &&
parent is IrClass &&
parent.isInline &&
field.name == parent.inlineClassFieldName) {
val receiver = expression.receiver!!.transform(this, null)
return coerceInlineClasses(receiver, receiver.type, field.type)
}
+11
View File
@@ -0,0 +1,11 @@
inline class A(val a: Int = 1) {
companion object {
val a: Int = 2
}
}
fun box(): String {
if (A.a != 2) return "FAIL1"
val instance = A()
return if (instance.a != 1) "FAIL2" else "OK"
}
@@ -18868,6 +18868,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt47609.kt");
}
@Test
@TestMetadata("kt47762.kt")
public void testKt47762() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47762.kt");
}
@Test
@TestMetadata("mangledDefaultParameterFunction.kt")
public void testMangledDefaultParameterFunction() throws Exception {
@@ -18910,6 +18910,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inlineClasses/kt47609.kt");
}
@Test
@TestMetadata("kt47762.kt")
public void testKt47762() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47762.kt");
}
@Test
@TestMetadata("mangledDefaultParameterFunction.kt")
public void testMangledDefaultParameterFunction() throws Exception {
@@ -15648,6 +15648,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/kt47609.kt");
}
@TestMetadata("kt47762.kt")
public void testKt47762() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47762.kt");
}
@TestMetadata("mangledDefaultParameterFunction.kt")
public void testMangledDefaultParameterFunction() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt");
@@ -13637,6 +13637,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/inlineClasses/kt46554.kt");
}
@TestMetadata("kt47762.kt")
public void testKt47762() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47762.kt");
}
@TestMetadata("mangledDefaultParameterFunction.kt")
public void testMangledDefaultParameterFunction() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt");
@@ -13043,6 +13043,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt46554.kt");
}
@TestMetadata("kt47762.kt")
public void testKt47762() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47762.kt");
}
@TestMetadata("mangledDefaultParameterFunction.kt")
public void testMangledDefaultParameterFunction() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt");
@@ -13108,6 +13108,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inlineClasses/kt46554.kt");
}
@TestMetadata("kt47762.kt")
public void testKt47762() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47762.kt");
}
@TestMetadata("mangledDefaultParameterFunction.kt")
public void testMangledDefaultParameterFunction() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt");
@@ -7158,6 +7158,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/inlineClasses/kt46554.kt");
}
@TestMetadata("kt47762.kt")
public void testKt47762() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt47762.kt");
}
@TestMetadata("mangledDefaultParameterFunction.kt")
public void testMangledDefaultParameterFunction() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt");