JVM IR: fix compound access to JvmField properties

This commit is contained in:
Alexander Udalov
2019-02-05 18:14:27 +01:00
committed by Alexander Udalov
parent 5c807266f6
commit 4bfa98144b
5 changed files with 40 additions and 3 deletions
@@ -61,13 +61,13 @@ private class ConstAndJvmFieldPropertiesLowering(val context: CommonBackendConte
private fun substituteSetter(irProperty: IrProperty, expression: IrCall): IrExpression {
val backingField = irProperty.backingField!!
val receiver = expression.dispatchReceiver?.let { super.visitExpression(it) }
val receiver = expression.dispatchReceiver?.transform(this, null)
val setExpr = IrSetFieldImpl(
expression.startOffset,
expression.endOffset,
backingField.symbol,
receiver,
super.visitExpression(expression.getValueArgument(expression.valueArgumentsCount - 1)!!),
expression.getValueArgument(expression.valueArgumentsCount - 1)!!.transform(this, null),
expression.type,
expression.origin,
expression.superQualifierSymbol
@@ -77,7 +77,7 @@ private class ConstAndJvmFieldPropertiesLowering(val context: CommonBackendConte
private fun substituteGetter(irProperty: IrProperty, expression: IrCall): IrExpression {
val backingField = irProperty.backingField!!
val receiver = expression.dispatchReceiver?.let { super.visitExpression(it) }
val receiver = expression.dispatchReceiver?.transform(this, null)
val getExpr = IrGetFieldImpl(
expression.startOffset,
expression.endOffset,
@@ -0,0 +1,22 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
class A {
@JvmField val b = B()
}
class B {
@JvmField val c = C()
@JvmField val result = "OK"
}
class C {
@JvmField var d = "Fail"
}
fun box(): String {
val a = A()
a.b.c.d = a.b.result
return a.b.c.d
}
@@ -14333,6 +14333,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/jvmField/classFieldReflection.kt");
}
@TestMetadata("compoundAccess.kt")
public void testCompoundAccess() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/compoundAccess.kt");
}
@TestMetadata("constructorProperty.kt")
public void testConstructorProperty() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/constructorProperty.kt");
@@ -14333,6 +14333,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/jvmField/classFieldReflection.kt");
}
@TestMetadata("compoundAccess.kt")
public void testCompoundAccess() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/compoundAccess.kt");
}
@TestMetadata("constructorProperty.kt")
public void testConstructorProperty() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/constructorProperty.kt");
@@ -14338,6 +14338,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/jvmField/classFieldReflection.kt");
}
@TestMetadata("compoundAccess.kt")
public void testCompoundAccess() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/compoundAccess.kt");
}
@TestMetadata("constructorProperty.kt")
public void testConstructorProperty() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/constructorProperty.kt");