K2 JVM IR: fix access to Java field shadowed by Kotlin property
#KT-56386 Fixed Co-authored-by: Mikhail Glukhikh <Mikhail.Glukhikh@jetbrains.com>
This commit is contained in:
+9
-4
@@ -1,3 +1,7 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_K1: JVM_IR
|
||||
// ^ See javaFields_k1.kt for a copy of this test for K1.
|
||||
|
||||
// FILE: Java1.java
|
||||
public class Java1 {
|
||||
public int f;
|
||||
@@ -16,8 +20,9 @@ open class Kotlin2 : Java2() {
|
||||
|
||||
fun test1(j: Kotlin2) = j.f
|
||||
|
||||
// @Kotlin2.class:
|
||||
// 1 GETFIELD Java2.f : I
|
||||
// K2 generates access to Java1.f in both cases. The main motivation for this is to fix cases like KT-49507.
|
||||
// Java1 in this case is the most specific Java superclass of Kotlin2 which has no Kotlin superclasses in its hierarchy.
|
||||
|
||||
// @TestKt.class:
|
||||
// 1 GETFIELD Kotlin2.f : I
|
||||
// 2 GETFIELD Java1.f : I
|
||||
// 0 GETFIELD Java2.f : I
|
||||
// 0 GETFIELD Kotlin2.f : I
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_K1: JVM_IR
|
||||
// ^ See javaFieldsWithIntersectionTypes_k1.kt for a copy of this test for K1.
|
||||
|
||||
// FILE: JFieldOwner.java
|
||||
|
||||
public class JFieldOwner {
|
||||
@@ -30,8 +34,9 @@ fun test(b : Boolean) {
|
||||
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 1 GETFIELD JFieldOwner.f : I
|
||||
// 1 PUTFIELD JFieldOwner.f : I
|
||||
// 1 GETFIELD Mid.f : I
|
||||
// 1 PUTFIELD Mid.f : I
|
||||
// K2 generates access to Java1.f in both cases. The main motivation for this is to fix cases like KT-49507.
|
||||
|
||||
// 2 GETFIELD JFieldOwner.f : I
|
||||
// 2 PUTFIELD JFieldOwner.f : I
|
||||
// 0 GETFIELD Mid.f : I
|
||||
// 0 PUTFIELD Mid.f : I
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// IGNORE_BACKEND_K2: JVM_IR
|
||||
// ^ See javaFieldsWithIntersectionTypes.kt for a copy of this test for K2.
|
||||
|
||||
// FILE: JFieldOwner.java
|
||||
|
||||
public class JFieldOwner {
|
||||
public int f;
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
interface IFoo
|
||||
|
||||
class Derived1 : JFieldOwner(), IFoo
|
||||
class Derived2 : JFieldOwner(), IFoo
|
||||
|
||||
open class Mid : JFieldOwner()
|
||||
class DerivedThroughMid1 : Mid(), IFoo
|
||||
class DerivedThroughMid2 : Mid(), IFoo
|
||||
|
||||
fun test(b : Boolean) {
|
||||
val d1 = Derived1()
|
||||
val d2 = Derived2()
|
||||
val k = if (b) d1 else d2
|
||||
k.f = 42
|
||||
k.f
|
||||
|
||||
val md1 = DerivedThroughMid1()
|
||||
val md2 = DerivedThroughMid2()
|
||||
val mk = if (b) md1 else md2
|
||||
mk.f = 44
|
||||
mk.f
|
||||
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 1 GETFIELD JFieldOwner.f : I
|
||||
// 1 PUTFIELD JFieldOwner.f : I
|
||||
// 1 GETFIELD Mid.f : I
|
||||
// 1 PUTFIELD Mid.f : I
|
||||
@@ -0,0 +1,26 @@
|
||||
// IGNORE_BACKEND_K2: JVM_IR
|
||||
// ^ See javaFields.kt for a copy of this test for K2.
|
||||
|
||||
// FILE: Java1.java
|
||||
public class Java1 {
|
||||
public int f;
|
||||
}
|
||||
|
||||
// FILE: Java2.java
|
||||
public class Java2 extends Kotlin1 {
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
open class Kotlin1 : Java1()
|
||||
|
||||
open class Kotlin2 : Java2() {
|
||||
fun getF() = super.f
|
||||
}
|
||||
|
||||
fun test1(j: Kotlin2) = j.f
|
||||
|
||||
// @Kotlin2.class:
|
||||
// 1 GETFIELD Java2.f : I
|
||||
|
||||
// @TestKt.class:
|
||||
// 1 GETFIELD Kotlin2.f : I
|
||||
Reference in New Issue
Block a user