JVM_IR KT-47326 downcast field receiver on JvmField lowering

This commit is contained in:
Dmitry Petrov
2021-06-18 17:55:51 +03:00
committed by TeamCityServer
parent ebc4e10684
commit c19792e7c5
24 changed files with 530 additions and 8 deletions
+17
View File
@@ -0,0 +1,17 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
interface A { val x: Int }
class B(@JvmField override val x: Int): A
class C<D: A>(@JvmField val d: D)
class E(c: C<B>) { val ax = c.d.x }
fun box(): String {
val e = E(C(B(42)))
if (e.ax != 42)
return "Failed: ${e.ax}"
return "OK"
}
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// ^ generates 'GETFIELD B.x : I' instead of 'GETFIELD BB.x : I'
// WITH_RUNTIME
interface A { val x: Int }
open class B(@JvmField override val x: Int): A
class BB(x: Int) : B(x)
class C<D: A>(@JvmField val d: D)
class E(c: C<BB>) { val ax = c.d.x }
// CHECK_BYTECODE_TEXT
// 1 GETFIELD BB\.x \: I
fun box(): String {
val e = E(C(BB(42)))
if (e.ax != 42)
return "Failed: ${e.ax}"
return "OK"
}
+18
View File
@@ -0,0 +1,18 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
interface A { val x: String }
open class B(@JvmField override val x: String): A
open class BB(x: String) : B(x)
class X(x: String) : A, BB(x) {
override val x: String
get() = super.x
}
fun box(): String {
val e = X("OK")
return e.x
}
+22
View File
@@ -0,0 +1,22 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
interface A { var x: Int }
class B(@JvmField override var x: Int): A
class C<D: A>(@JvmField val d: D)
class E(c: C<B>) {
init {
c.d.x = 42
}
val ax = c.d.x
}
fun box(): String {
val e = E(C(B(1234)))
if (e.ax != 42)
return "Failed: ${e.ax}"
return "OK"
}
+3
View File
@@ -1,5 +1,8 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// - FIR2IR should generate call to fake override
// WITH_RUNTIME
// FILE: 1.kt
+3
View File
@@ -1,5 +1,8 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// - FIR2IR should generate call to fake override
// WITH_RUNTIME
// FILE: 1.kt
@@ -1,6 +1,9 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
// - FIR2IR should generate call to fake override
// FILE: A.kt
package a
import b.*
@@ -1,6 +1,9 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
// - FIR2IR should generate call to fake override
// FILE: a.kt
package a
@@ -1,6 +1,9 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
// - FIR2IR should generate call to fake override
// FILE: a.kt
package a
+9
View File
@@ -0,0 +1,9 @@
// WITH_RUNTIME
interface A { val x: Int }
class B(@JvmField override val x: Int): A
class C<D: A>(@JvmField val d: D)
class E(c: C<B>) { val ax = c.d.x }
+27
View File
@@ -0,0 +1,27 @@
@kotlin.Metadata
public interface A {
// source: 'kt47328.kt'
public abstract method getX(): int
}
@kotlin.Metadata
public final class B {
// source: 'kt47328.kt'
public final @kotlin.jvm.JvmField field x: int
public method <init>(p0: int): void
}
@kotlin.Metadata
public final class C {
// source: 'kt47328.kt'
public final @kotlin.jvm.JvmField @org.jetbrains.annotations.NotNull field d: A
public method <init>(@org.jetbrains.annotations.NotNull p0: A): void
}
@kotlin.Metadata
public final class E {
// source: 'kt47328.kt'
private final field ax: int
public method <init>(@org.jetbrains.annotations.NotNull p0: C): void
public final method getAx(): int
}