JVM_IR KT-48295 don't upcast field receiver with super qualifier

This commit is contained in:
Dmitry Petrov
2021-08-19 12:57:42 +03:00
committed by TeamCityServer
parent 7038b02933
commit a3bb9dde45
7 changed files with 93 additions and 1 deletions
@@ -24782,6 +24782,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/jvmField/kt47739.kt");
}
@Test
@TestMetadata("kt48295.kt")
public void testKt48295() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/kt48295.kt");
}
@Test
@TestMetadata("kt48295a.kt")
public void testKt48295a() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/kt48295a.kt");
}
@Test
@TestMetadata("publicField.kt")
public void testPublicField() throws Exception {
@@ -116,7 +116,9 @@ class JvmPropertiesLowering(private val backendContext: JvmBackendContext) : IrE
val receiver = expression.dispatchReceiver
if (receiver != null) {
val propertyParent = irProperty.parent
if (propertyParent is IrClass && propertyParent.symbol != receiver.type.classifierOrNull) {
if (propertyParent is IrClass && propertyParent.symbol != receiver.type.classifierOrNull &&
expression.superQualifierSymbol == null
) {
return irImplicitCast(receiver, propertyParent.defaultType)
}
}
+21
View File
@@ -0,0 +1,21 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: a.kt
package a
open class A {
@JvmField protected var result = "Fail"
}
// FILE: b.kt
class B : a.A() {
fun test(): String {
super.result = "OK"
return super.result
}
}
fun box(): String = B().test()
+23
View File
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: a.kt
package a
open class A {
@JvmField protected var result = "Fail"
}
open class AA : A()
// FILE: b.kt
class B : a.AA() {
fun test(): String {
super.result = "OK"
return super.result
}
}
fun box(): String = B().test()
@@ -24632,6 +24632,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/jvmField/kt47739.kt");
}
@Test
@TestMetadata("kt48295.kt")
public void testKt48295() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/kt48295.kt");
}
@Test
@TestMetadata("kt48295a.kt")
public void testKt48295a() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/kt48295a.kt");
}
@Test
@TestMetadata("publicField.kt")
public void testPublicField() throws Exception {
@@ -24782,6 +24782,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/jvmField/kt47739.kt");
}
@Test
@TestMetadata("kt48295.kt")
public void testKt48295() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/kt48295.kt");
}
@Test
@TestMetadata("kt48295a.kt")
public void testKt48295a() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/kt48295a.kt");
}
@Test
@TestMetadata("publicField.kt")
public void testPublicField() throws Exception {
@@ -20763,6 +20763,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/jvmField/kt47739.kt");
}
@TestMetadata("kt48295.kt")
public void testKt48295() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/kt48295.kt");
}
@TestMetadata("kt48295a.kt")
public void testKt48295a() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/kt48295a.kt");
}
@TestMetadata("publicField.kt")
public void testPublicField() throws Exception {
runTest("compiler/testData/codegen/box/jvmField/publicField.kt");