[IR] Support reflection for MFVC

Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>

#KT-1179
This commit is contained in:
Evgeniy.Zhelenskiy
2023-03-02 01:48:02 +01:00
committed by Space Team
parent 1ff4906880
commit 88f293d4a9
52 changed files with 2910 additions and 172 deletions
@@ -0,0 +1,51 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.test.assertEquals
@JvmInline
value class Z(val x1: UInt, val x2: Int)
class Outer(val z1: Z, val z2: Z?) {
inner class Inner(val z3: Z, val z4: Z?) {
val test = "$z1 $z2 $z3 $z4"
}
}
@JvmInline
value class ValueNonNullOuter(val z11: Z, val z12: Z) {
class Inner(val t: ValueNonNullOuter, val z2: Z, val z3: Z?) {
val test = "${t.z11} ${t.z12} $z2 $z3"
}
}
@JvmInline
value class ValueNullableOuter(val z11: Z?, val z12: Z?) {
class Inner(val t: ValueNullableOuter, val z2: Z, val z3: Z?) {
val test = "${t.z11} ${t.z12} $z2 $z3"
}
}
fun box(): String {
val z1 = Z(1U, -1)
val z2 = Z(2U, -2)
val z3 = Z(3U, -3)
val z4 = Z(4U, -4)
val outer = ::Outer.call(z1, z2)
assertEquals(z1, outer.z1)
assertEquals(z2, outer.z2)
assertEquals("Z(x1=1, x2=-1) Z(x1=2, x2=-2) Z(x1=3, x2=-3) Z(x1=4, x2=-4)", Outer::Inner.call(outer, z3, z4).test)
assertEquals("Z(x1=1, x2=-1) Z(x1=2, x2=-2) Z(x1=2, x2=-2) Z(x1=4, x2=-4)", outer::Inner.call(z2, z4).test)
val valueNonNullOuter = ValueNonNullOuter(z1, z4)
assertEquals("Z(x1=1, x2=-1) Z(x1=4, x2=-4) Z(x1=2, x2=-2) Z(x1=3, x2=-3)", ValueNonNullOuter::Inner.call(valueNonNullOuter, z2, z3).test)
val valueNullableOuter = ValueNullableOuter(z1, z4)
assertEquals("Z(x1=1, x2=-1) Z(x1=4, x2=-4) Z(x1=2, x2=-2) Z(x1=3, x2=-3)", ValueNullableOuter::Inner.call(valueNullableOuter, z2, z3).test)
return "OK"
}
@@ -0,0 +1,59 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.reflect.jvm.isAccessible
import kotlin.test.assertEquals
@JvmInline
value class S(val value1: UInt, val value2: Int) {
operator fun plus(other: S): S = S(this.value1 + other.value1, this.value2 + other.value2)
}
class C {
private var nonNullMember: S = S(UInt.MAX_VALUE, -10)
private var nullableMember: S? = S(UInt.MAX_VALUE, -10)
fun nonNullUnboundRef() = C::nonNullMember.apply { isAccessible = true }
fun nonNullBoundRef() = this::nonNullMember.apply { isAccessible = true }
fun nullableUnboundRef() = C::nullableMember.apply { isAccessible = true }
fun nullableBoundRef() = this::nullableMember.apply { isAccessible = true }
}
private var nonNullTopLevel: S = S(UInt.MAX_VALUE, -10)
private var nullableTopLevel: S? = S(UInt.MAX_VALUE, -10)
fun box(): String {
val c = C()
val zero = S(0U, 5)
val one = S(1U, 10)
val two = S(2U, 20)
assertEquals(Unit, c.nonNullUnboundRef().setter.call(c, zero))
assertEquals(zero, c.nonNullUnboundRef().call(c))
assertEquals(zero, c.nonNullUnboundRef().getter.call(c))
assertEquals(Unit, c.nonNullBoundRef().setter.call(one))
assertEquals(one, c.nonNullBoundRef().call())
assertEquals(one, c.nonNullBoundRef().getter.call())
assertEquals(Unit, c.nullableUnboundRef().setter.call(c, zero))
assertEquals(zero, c.nullableUnboundRef().call(c))
assertEquals(zero, c.nullableUnboundRef().getter.call(c))
assertEquals(Unit, c.nullableBoundRef().setter.call(one))
assertEquals(one, c.nullableBoundRef().call())
assertEquals(one, c.nullableBoundRef().getter.call())
val nonNullTopLevel = ::nonNullTopLevel.apply { isAccessible = true }
assertEquals(Unit, nonNullTopLevel.setter.call(two))
assertEquals(two, nonNullTopLevel.call())
assertEquals(two, nonNullTopLevel.getter.call())
val nullableTopLevel = ::nullableTopLevel.apply { isAccessible = true }
assertEquals(Unit, nullableTopLevel.setter.call(two))
assertEquals(two, nullableTopLevel.call())
assertEquals(two, nullableTopLevel.getter.call())
return "OK"
}
@@ -0,0 +1,53 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.test.assertEquals
@JvmInline
value class S(val value1: UInt, val value2: Int) {
operator fun plus(other: S): S = S(this.value1 + other.value1, this.value2 + other.value2)
}
class C {
fun member(x: S, y1: UInt, y2: Int, z: S?): S = x + S(y1, y2) + z!!
}
fun topLevel(x1: UInt, x2: Int, y: S, z: S?): S = S(x1, x2) + y + z!!
fun S.extension1(y: S, z: S?): S = this + y + z!!
fun S?.extension2(y: S, z: S?) = this!! + y + z!!
fun S.extension3_1(): UInt = value1
fun S.extension3_2(): Int = value2
fun S?.extension4_1(): UInt = this!!.value1
fun S?.extension4_2(): Int = this!!.value2
fun box(): String {
val zero = S(0U, 1000)
val one = S(1U, -1)
val two = S(2U, -2)
val four = S(4U, -4)
val seven = S(7U, -7)
assertEquals(seven, C::member.call(C(), one, 2U, -2, four))
assertEquals(seven, ::topLevel.call(1U, -1, two, four))
assertEquals(seven, S::extension1.call(one, two, four))
assertEquals(seven, S::extension2.call(one, two, four))
assertEquals(0U, S::extension3_1.call(zero))
assertEquals(1000, S::extension3_2.call(zero))
assertEquals(0U, S?::extension4_1.call(zero))
assertEquals(1000, S?::extension4_2.call(zero))
assertEquals(seven, C()::member.call(one, 2U, -2, four))
assertEquals(seven, one::extension1.call(two, four))
assertEquals(seven, one::extension2.call(two, four))
assertEquals(0U, zero::extension3_1.call())
assertEquals(1000, zero::extension3_2.call())
assertEquals(0U, zero::extension4_1.call())
assertEquals(1000, zero::extension4_2.call())
return "OK"
}
@@ -0,0 +1,74 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.test.assertEquals
@JvmInline
value class Z(internal val x1: UInt, internal val x2: Int)
@JvmInline
value class Z2(internal val x1: Z, internal val x2: Z)
@JvmInline
value class L(internal val x1: ULong, internal val x2: Long)
@JvmInline
value class L2(internal val x1: L, internal val x2: L)
@JvmInline
value class A1(internal val x1: Any?, internal val x2: Any?)
@JvmInline
value class A1_2(internal val x1: A1, internal val x2: A1)
@JvmInline
value class A2(internal val x1: Any, internal val x2: Any)
@JvmInline
value class A2_2(internal val x1: A2, internal val x2: A2)
fun box(): String {
assertEquals(42U, Z::x1.call(Z(42U, 43)))
assertEquals(43, Z::x2.call(Z(42U, 43)))
assertEquals(42U, Z(42U, 43)::x1.call())
assertEquals(43, Z(42U, 43)::x2.call())
assertEquals(1234UL, L::x1.call(L(1234UL, 5678L)))
assertEquals(5678L, L::x2.call(L(1234UL, 5678L)))
assertEquals(1234UL, L(1234UL, 5678L)::x1.call())
assertEquals(5678L, L(1234UL, 5678L)::x2.call())
assertEquals("abc", A1::x1.call(A1("abc", "def")))
assertEquals("def", A1::x2.call(A1("abc", "def")))
assertEquals("abc", A1("abc", "def")::x1.call())
assertEquals("def", A1("abc", "def")::x2.call())
assertEquals(null, A1::x1.call(A1(null, null)))
assertEquals(null, A1::x2.call(A1(null, null)))
assertEquals(null, A1(null, null)::x1.call())
assertEquals(null, A1(null, null)::x2.call())
assertEquals("abc", A2::x1.call(A2("abc", "def")))
assertEquals("def", A2::x2.call(A2("abc", "def")))
assertEquals("abc", A2("abc", "def")::x1.call())
assertEquals("def", A2("abc", "def")::x2.call())
assertEquals(Z(42U, 43), Z2::x1.call(Z2(Z(42U, 43), Z(44U, 45))))
assertEquals(Z(44U, 45), Z2::x2.call(Z2(Z(42U, 43), Z(44U, 45))))
assertEquals(Z(42U, 43), Z2(Z(42U, 43), Z(44U, 45))::x1.call())
assertEquals(Z(44U, 45), Z2(Z(42U, 43), Z(44U, 45))::x2.call())
assertEquals(L(1234UL, 5678L), L2::x1.call(L2(L(1234UL, 5678L), L(12340UL, -5678L))))
assertEquals(L(12340UL, -5678L), L2::x2.call(L2(L(1234UL, 5678L), L(12340UL, -5678L))))
assertEquals(L(1234UL, 5678L), L2(L(1234UL, 5678L), L(12340UL, -5678L))::x1.call())
assertEquals(L(12340UL, -5678L), L2(L(1234UL, 5678L), L(12340UL, -5678L))::x2.call())
assertEquals(A1("abc", "def"), A1_2::x1.call(A1_2(A1("abc", "def"), A1("geh", "ijk"))))
assertEquals(A1("geh", "ijk"), A1_2::x2.call(A1_2(A1("abc", "def"), A1("geh", "ijk"))))
assertEquals(A1("abc", "def"), A1_2(A1("abc", "def"), A1("geh", "ijk"))::x1.call())
assertEquals(A1("geh", "ijk"), A1_2(A1("abc", "def"), A1("geh", "ijk"))::x2.call())
assertEquals(A1(null, null), A1_2::x1.call(A1_2(A1(null, null), A1(null, null))))
assertEquals(A1(null, null), A1_2::x2.call(A1_2(A1(null, null), A1(null, null))))
assertEquals(A1(null, null), A1_2(A1(null, null), A1(null, null))::x1.call())
assertEquals(A1(null, null), A1_2(A1(null, null), A1(null, null))::x2.call())
assertEquals(A2("abc", "def"), A2_2::x1.call(A2_2(A2("abc", "def"), A2("geh", "ijk"))))
assertEquals(A2("geh", "ijk"), A2_2::x2.call(A2_2(A2("abc", "def"), A2("geh", "ijk"))))
assertEquals(A2("abc", "def"), A2_2(A2("abc", "def"), A2("geh", "ijk"))::x1.call())
assertEquals(A2("geh", "ijk"), A2_2(A2("abc", "def"), A2("geh", "ijk"))::x2.call())
return "OK"
}
@@ -0,0 +1,53 @@
// TARGET_BACKEND: JVM_IR
// JVM_TARGET: 1.8
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.jvm.isAccessible
import kotlin.test.assertEquals
@JvmInline
value class Z(val value1: UInt, val value2: Int) {
operator fun plus(other: Z): Z = Z(this.value1 + other.value1, this.value2 + other.value2)
}
object C {
@JvmStatic
private var p1: Z = Z(UInt.MAX_VALUE, -10)
@JvmStatic
private var p2: Z? = Z(UInt.MAX_VALUE, -10)
fun nonNullBoundRef() = this::p1.apply { isAccessible = true }
fun nullableBoundRef() = this::p2.apply { isAccessible = true }
}
fun box(): String {
val one = Z(1U, 10)
val two = Z(2U, 20)
val nonNullUnboundRef = C::class.members.single { it.name == "p1" } as KMutableProperty1<C, Z>
nonNullUnboundRef.isAccessible = true
assertEquals(Unit, nonNullUnboundRef.setter.call(C, one))
assertEquals(one, nonNullUnboundRef.call(C))
assertEquals(one, nonNullUnboundRef.getter.call(C))
val nullableUnboundRef = C::class.members.single { it.name == "p2" } as KMutableProperty1<C, Z?>
nullableUnboundRef.isAccessible = true
assertEquals(Unit, nullableUnboundRef.setter.call(C, one))
assertEquals(one, nullableUnboundRef.call(C))
assertEquals(one, nullableUnboundRef.getter.call(C))
val nonNullBoundRef = C.nonNullBoundRef()
assertEquals(Unit, nonNullBoundRef.setter.call(two))
assertEquals(two, nonNullBoundRef.call())
assertEquals(two, nonNullBoundRef.getter.call())
val nullableBoundRef = C.nullableBoundRef()
assertEquals(Unit, nullableBoundRef.setter.call(two))
assertEquals(two, nullableBoundRef.call())
assertEquals(two, nullableBoundRef.getter.call())
return "OK"
}
@@ -0,0 +1,42 @@
// TARGET_BACKEND: JVM_IR
// JVM_TARGET: 1.8
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.reflect.KFunction
import kotlin.test.assertEquals
@JvmInline
value class Z(val value1: UInt, val value2: Int) {
operator fun plus(other: Z): Z = Z(this.value1 + other.value1, this.value2 + other.value2)
}
object C {
@JvmStatic
fun foo(x: Z, y1: UInt, y2: Int, z: Z?): Z = x + Z(y1, y2) + z!!
}
interface I {
companion object {
@JvmStatic
fun bar(x1: UInt, x2: Int, y: Z, z: Z?): Z = Z(x1, x2) + y + z!!
}
}
fun box(): String {
val one = Z(1U, -1)
val two = Z(2U, -2)
val four = Z(4U, -4)
val seven = Z(7U, -7)
assertEquals(seven, C::foo.call(one, 2U, -2, four))
assertEquals(seven, (I)::bar.call(1U, -1, two, four))
val unboundFoo = C::class.members.single { it.name == "foo" } as KFunction<*>
assertEquals(seven, unboundFoo.call(C, one, 2U, -2, four))
val unboundBar = I.Companion::class.members.single { it.name == "bar" } as KFunction<*>
assertEquals(seven, unboundBar.call(I, 1U, -1, two, four))
return "OK"
}
@@ -0,0 +1,82 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.reflect.KCallable
import kotlin.test.assertEquals
@JvmInline
value class Z(val x1: UInt, val x2: Int) {
constructor(a: UInt, b: UInt, c: Int, d: Int) : this(a + b, c + d)
}
@JvmInline
value class L(val x1: ULong, val x2: Long) {
constructor(a: ULong, b: ULong, c: Long, d: Long) : this(a + b, c + d)
}
@JvmInline
value class S1(val x1: String, val x2: String) {
constructor(a: String, b: String, c: String, d: String) : this(a + b, c + d)
}
@JvmInline
value class S2(val x1: String?, val x2: String?) {
constructor(a: String?, b: String?, c: String?, d: String?) : this(a!! + b!!, c!! + d!!)
}
@JvmInline
value class A(val x1: Any, val x2: Any) {
constructor(a: String, b: String, c: String, d: String) : this(a + b, c + d)
}
@JvmInline
value class Z2(val z1: Z, val z2: Z) {
constructor(z1: Z, z2: Z, z3: Z, z4: Z) : this(Z(z1.x1 + z2.x1, z1.x2 + z2.x2), Z(z3.x1 + z4.x1, z3.x2 + z4.x2))
}
@JvmInline
value class Z3(val z1: Z?, val z2: Z?) {
constructor(z1: Z?, z2: Z?, z3: Z?, z4: Z?) : this(Z(z1!!.x1 + z2!!.x1, z1!!.x2 + z2!!.x2), Z(z3!!.x1 + z4!!.x1, z3!!.x2 + z4!!.x2))
}
fun box(): String {
val ctorZ1_1: (UInt, Int) -> Z = ::Z
val ctorZ1_2: (UInt, UInt, Int, Int) -> Z = ::Z
val ctorL1: (ULong, Long) -> L = ::L
val ctorL2: (ULong, ULong, Long, Long) -> L = ::L
val ctorS1_1: (String, String) -> S1 = ::S1
val ctorS1_2: (String, String, String, String) -> S1 = ::S1
val ctorS2_1: (String, String) -> S2 = ::S2
val ctorS2_2: (String, String, String, String) -> S2 = ::S2
val ctorA1: (Any, Any) -> A = ::A
val ctorA2: (String, String, String, String) -> A = ::A
val ctorZ2_2: (Z, Z) -> Z2 = ::Z2
val ctorZ2_4: (Z, Z, Z, Z) -> Z2 = ::Z2
val ctorZ3_2: (Z, Z) -> Z3 = ::Z3
val ctorZ3_4: (Z, Z, Z, Z) -> Z3 = ::Z3
assertEquals(Z(42U, 43), (ctorZ1_1 as KCallable<Z>).call(42U, 43))
assertEquals(Z(123U, 224), (ctorZ1_2 as KCallable<Z>).call(100U, 23U, 200, 24))
assertEquals(L(1UL, 2L), (ctorL1 as KCallable<L>).call(1UL, 2L))
assertEquals(L(123UL, 224L), (ctorL2 as KCallable<L>).call(100UL, 23UL, 200L, 24L))
assertEquals(S1("abc", "def"), (ctorS1_1 as KCallable<S1>).call("abc", "def"))
assertEquals(S1("abc", "def"), (ctorS1_2 as KCallable<S1>).call("ab", "c", "de", "f"))
assertEquals(S2("abc", "def"), (ctorS2_1 as KCallable<S2>).call("abc", "def"))
assertEquals(S2("abc", "def"), (ctorS2_2 as KCallable<S2>).call("ab", "c", "de", "f"))
assertEquals(A("abc", "def"), (ctorA1 as KCallable<A>).call("abc", "def"))
assertEquals(A("abc", "def"), (ctorA2 as KCallable<A>).call("a", "bc", "d", "ef"))
assertEquals(Z2(Z(42U, 43), Z(44U, 45)), (ctorZ2_2 as KCallable<Z2>).call(Z(42U, 43), Z(44U, 45)))
assertEquals(Z3(Z(42U, 43), Z(44U, 45)), (ctorZ3_2 as KCallable<Z3>).call(Z(42U, 43), Z(44U, 45)))
assertEquals(
Z2(Z(142U, 243), Z(344U, 445)),
(ctorZ2_4 as KCallable<Z2>).call(Z(42U, 43), Z(100U, 200), Z(44U, 45), Z(300U, 400))
)
assertEquals(
Z3(Z(142U, 243), Z(344U, 445)),
(ctorZ3_4 as KCallable<Z3>).call(Z(42U, 43), Z(100U, 200), Z(44U, 45), Z(300U, 400))
)
return "OK"
}
@@ -0,0 +1,37 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.test.assertEquals
@JvmInline
value class Z(val x1: UInt, val x2: Int) {
fun test(a: Int, b: Z, c: Z?) = "$x1$x2$a${b.x1}${b.x2}${c!!.x1}${c!!.x2}"
}
@JvmInline
value class S(val x1: String, val x2: String) {
fun test(a: Int, b: Z, c: Z?) = "$x1$x2$a${b.x1}${b.x2}${c!!.x1}${c!!.x2}"
}
@JvmInline
value class A(val x1: Any, val x2: Any) {
fun test(a: Int, b: Z, c: Z?) = "$x1$x2$a${b.x1}${b.x2}${c!!.x1}${c!!.x2}"
}
fun box(): String {
val two = Z(2U, 3)
val four = Z(4U, 5)
val expected = "0912345"
assertEquals(expected, Z::test.call(Z(0U, 9), 1, two, four))
assertEquals(expected, Z(0U, 9)::test.call(1, two, four))
assertEquals(expected, S::test.call(S("0", "9"), 1, two, four))
assertEquals(expected, S("0", "9")::test.call(1, two, four))
assertEquals(expected, A::test.call(A(0U, 9), 1, two, four))
assertEquals(expected, A(0U, 9)::test.call(1, two, four))
return "OK"
}
@@ -0,0 +1,127 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.test.assertEquals
var global = Z(0U, 0)
@JvmInline
value class Z(val x1: UInt, val x2: Int) {
var nonNullTest: Z
get() = Z(global.x1 + this.x1, global.x2 + this.x2)
set(value) {
global = Z(this.x1 + value.x1, this.x2 + value.x2)
}
var nullableTest: Z?
get() = Z(global.x1 + this.x1, global.x2 + this.x2)
set(value) {
global = Z(this.x1 + value!!.x1, this.x2 + value!!.x2)
}
}
@JvmInline
value class S(val x1: String, val x2: String) {
var nonNullTest: Z
get() = Z(global.x1 + x1.toUInt(), global.x2 + x2.toInt())
set(value) {
global = Z(this.x1.toUInt() + value.x1, this.x2.toInt() + value.x2)
}
var nullableTest: Z?
get() = Z(global.x1 + x1.toUInt(), global.x2 + x2.toInt())
set(value) {
global = Z(this.x1.toUInt() + value!!.x1, this.x2.toInt() + value!!.x2)
}
}
@JvmInline
value class A(val x1: Any, val x2: Any) {
var nonNullTest: Z
get() = Z(global.x1 + this.x1 as UInt, global.x2 + this.x2 as Int)
set(value) {
global = Z(this.x1 as UInt + value.x1, this.x2 as Int + value.x2)
}
var nullableTest: Z?
get() = Z(global.x1 + this.x1 as UInt, global.x2 + this.x2 as Int)
set(value) {
global = Z(this.x1 as UInt + value!!.x1, this.x2 as Int + value!!.x2)
}
}
fun box(): String {
val zZero = Z(0U, 0)
val zOne = Z(1U, -1)
val zTwo = Z(2U, -2)
val zThree = Z(3U, -3)
val zFour = Z(4U, -4)
val sOne = S("1", "-1")
val aOne = A(1U, -1)
global = zZero
assertEquals(zOne, Z::nonNullTest.call(zOne))
assertEquals(zOne, zOne::nonNullTest.call())
assertEquals(zOne, Z::nonNullTest.getter.call(zOne))
assertEquals(zOne, zOne::nonNullTest.getter.call())
Z::nonNullTest.setter.call(zOne, zTwo)
assertEquals(zThree, global)
zOne::nonNullTest.setter.call(zThree)
assertEquals(zFour, global)
global = zZero
assertEquals(zOne, Z::nullableTest.call(zOne))
assertEquals(zOne, zOne::nullableTest.call())
assertEquals(zOne, Z::nullableTest.getter.call(zOne))
assertEquals(zOne, zOne::nullableTest.getter.call())
Z::nullableTest.setter.call(zOne, zTwo)
assertEquals(zThree, global)
zOne::nullableTest.setter.call(zThree)
assertEquals(zFour, global)
global = zZero
assertEquals(zOne, S::nonNullTest.call(sOne))
assertEquals(zOne, sOne::nonNullTest.call())
assertEquals(zOne, S::nonNullTest.getter.call(sOne))
assertEquals(zOne, sOne::nonNullTest.getter.call())
S::nonNullTest.setter.call(sOne, zTwo)
assertEquals(zThree, global)
sOne::nonNullTest.setter.call(zThree)
assertEquals(zFour, global)
global = zZero
assertEquals(zOne, S::nullableTest.call(sOne))
assertEquals(zOne, sOne::nullableTest.call())
assertEquals(zOne, S::nullableTest.getter.call(sOne))
assertEquals(zOne, sOne::nullableTest.getter.call())
S::nullableTest.setter.call(sOne, zTwo)
assertEquals(zThree, global)
sOne::nullableTest.setter.call(zThree)
assertEquals(zFour, global)
global = zZero
assertEquals(zOne, A::nonNullTest.call(aOne))
assertEquals(zOne, aOne::nonNullTest.call())
assertEquals(zOne, A::nonNullTest.getter.call(aOne))
assertEquals(zOne, aOne::nonNullTest.getter.call())
A::nonNullTest.setter.call(aOne, zTwo)
assertEquals(zThree, global)
aOne::nonNullTest.setter.call(zThree)
assertEquals(zFour, global)
global = zZero
assertEquals(zOne, A::nullableTest.call(aOne))
assertEquals(zOne, aOne::nullableTest.call())
assertEquals(zOne, A::nullableTest.getter.call(aOne))
assertEquals(zOne, aOne::nullableTest.getter.call())
A::nullableTest.setter.call(aOne, zTwo)
assertEquals(zThree, global)
aOne::nullableTest.setter.call(zThree)
assertEquals(zFour, global)
return "OK"
}
@@ -0,0 +1,40 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.test.assertEquals
interface ITest {
fun test(a: Int, b: Z, c: Z?): String
}
@JvmInline
value class Z(val x1: UInt, val x2: Int) : ITest {
override fun test(a: Int, b: Z, c: Z?) = "$x1$x2$a${b.x1}${b.x2}${c!!.x1}${c!!.x2}"
}
@JvmInline
value class S(val x1: String, val x2: String) : ITest {
override fun test(a: Int, b: Z, c: Z?) = "$x1$x2$a${b.x1}${b.x2}${c!!.x1}${c!!.x2}"
}
@JvmInline
value class A(val x1: Any, val x2: Any) : ITest {
override fun test(a: Int, b: Z, c: Z?) = "$x1$x2$a${b.x1}${b.x2}${c!!.x1}${c!!.x2}"
}
fun box(): String {
val two = Z(2U, 3)
val four = Z(4U, 5)
assertEquals("0912345", Z::test.call(Z(0U, 9), 1, two, four))
assertEquals("0912345", Z(0U, 9)::test.call(1, two, four))
assertEquals("0912345", S::test.call(S("0", "9"), 1, two, four))
assertEquals("0912345", S("0", "9")::test.call(1, two, four))
assertEquals("0912345", A::test.call(A(0U, 9), 1, two, four))
assertEquals("0912345", A(0U, 9)::test.call(1, two, four))
return "OK"
}
@@ -0,0 +1,132 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.test.assertEquals
var global = Z(0U, 0)
interface ITest {
var nonNullTest: Z
var nullableTest: Z?
}
@JvmInline
value class Z(val x1: UInt, val x2: Int) : ITest {
override var nonNullTest: Z
get() = Z(global.x1 + this.x1, global.x2 + this.x2)
set(value) {
global = Z(this.x1 + value.x1, this.x2 + value.x2)
}
override var nullableTest: Z?
get() = Z(global.x1 + this.x1, global.x2 + this.x2)
set(value) {
global = Z(this.x1 + value!!.x1, this.x2 + value!!.x2)
}
}
@JvmInline
value class S(val x1: String, val x2: String) : ITest {
override var nonNullTest: Z
get() = Z(global.x1 + x1.toUInt(), global.x2 + x2.toInt())
set(value) {
global = Z(this.x1.toUInt() + value.x1, this.x2.toInt() + value.x2)
}
override var nullableTest: Z?
get() = Z(global.x1 + x1.toUInt(), global.x2 + x2.toInt())
set(value) {
global = Z(this.x1.toUInt() + value!!.x1, this.x2.toInt() + value!!.x2)
}
}
@JvmInline
value class A(val x1: Any, val x2: Any) : ITest {
override var nonNullTest: Z
get() = Z(global.x1 + this.x1 as UInt, global.x2 + this.x2 as Int)
set(value) {
global = Z(this.x1 as UInt + value.x1, this.x2 as Int + value.x2)
}
override var nullableTest: Z?
get() = Z(global.x1 + this.x1 as UInt, global.x2 + this.x2 as Int)
set(value) {
global = Z(this.x1 as UInt + value!!.x1, this.x2 as Int + value!!.x2)
}
}
fun box(): String {
val zZero = Z(0U, 0)
val zOne = Z(1U, -1)
val zTwo = Z(2U, -2)
val zThree = Z(3U, -3)
val zFour = Z(4U, -4)
val sOne = S("1", "-1")
val aOne = A(1U, -1)
global = zZero
assertEquals(zOne, Z::nonNullTest.call(zOne))
assertEquals(zOne, zOne::nonNullTest.call())
assertEquals(zOne, Z::nonNullTest.getter.call(zOne))
assertEquals(zOne, zOne::nonNullTest.getter.call())
Z::nonNullTest.setter.call(zOne, zTwo)
assertEquals(zThree, global)
zOne::nonNullTest.setter.call(zThree)
assertEquals(zFour, global)
global = zZero
assertEquals(zOne, Z::nullableTest.call(zOne))
assertEquals(zOne, zOne::nullableTest.call())
assertEquals(zOne, Z::nullableTest.getter.call(zOne))
assertEquals(zOne, zOne::nullableTest.getter.call())
Z::nullableTest.setter.call(zOne, zTwo)
assertEquals(zThree, global)
zOne::nullableTest.setter.call(zThree)
assertEquals(zFour, global)
global = zZero
assertEquals(zOne, S::nonNullTest.call(sOne))
assertEquals(zOne, sOne::nonNullTest.call())
assertEquals(zOne, S::nonNullTest.getter.call(sOne))
assertEquals(zOne, sOne::nonNullTest.getter.call())
S::nonNullTest.setter.call(sOne, zTwo)
assertEquals(zThree, global)
sOne::nonNullTest.setter.call(zThree)
assertEquals(zFour, global)
global = zZero
assertEquals(zOne, S::nullableTest.call(sOne))
assertEquals(zOne, sOne::nullableTest.call())
assertEquals(zOne, S::nullableTest.getter.call(sOne))
assertEquals(zOne, sOne::nullableTest.getter.call())
S::nullableTest.setter.call(sOne, zTwo)
assertEquals(zThree, global)
sOne::nullableTest.setter.call(zThree)
assertEquals(zFour, global)
global = zZero
assertEquals(zOne, A::nonNullTest.call(aOne))
assertEquals(zOne, aOne::nonNullTest.call())
assertEquals(zOne, A::nonNullTest.getter.call(aOne))
assertEquals(zOne, aOne::nonNullTest.getter.call())
A::nonNullTest.setter.call(aOne, zTwo)
assertEquals(zThree, global)
aOne::nonNullTest.setter.call(zThree)
assertEquals(zFour, global)
global = zZero
assertEquals(zOne, A::nullableTest.call(aOne))
assertEquals(zOne, aOne::nullableTest.call())
assertEquals(zOne, A::nullableTest.getter.call(aOne))
assertEquals(zOne, aOne::nullableTest.getter.call())
A::nullableTest.setter.call(aOne, zTwo)
assertEquals(zThree, global)
aOne::nullableTest.setter.call(zThree)
assertEquals(zFour, global)
return "OK"
}
@@ -0,0 +1,180 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.test.assertEquals
@JvmInline
value class Z(val x1: UInt, val x2: Int) {
var x3
get() = x1
set(value) = Unit
}
@JvmInline
value class Z2(val x1: Z, val x2: Z) {
var x3
get() = x1
set(value) = Unit
}
@JvmInline
value class L(val x1: ULong, val x2: Long) {
var x3
get() = x1
set(value) = Unit
}
@JvmInline
value class L2(val x1: L, val x2: L) {
var x3
get() = x1
set(value) = Unit
}
@JvmInline
value class A1(val x1: Any?, val x2: Any?) {
var x3
get() = x1
set(value) = Unit
}
@JvmInline
value class A1_2(val x1: A1, val x2: A1) {
var x3
get() = x1
set(value) = Unit
}
@JvmInline
value class A2(val x1: Any, val x2: Any) {
var x3
get() = x1
set(value) = Unit
}
@JvmInline
value class A2_2(val x1: A2, val x2: A2) {
var x3
get() = x1
set(value) = Unit
}
fun box(): String {
assertEquals(42U, Z::x1.call(Z(42U, 43)))
assertEquals(43, Z::x2.call(Z(42U, 43)))
assertEquals(42U, Z::x3.call(Z(42U, 43)))
assertEquals(42U, Z::x3.getter.call(Z(42U, 43)))
assertEquals(Unit, Z::x3.setter.call(Z(42U, 43), 42U))
assertEquals(42U, Z(42U, 43)::x1.call())
assertEquals(43, Z(42U, 43)::x2.call())
assertEquals(42U, Z(42U, 43)::x3.call())
assertEquals(42U, Z(42U, 43)::x3.getter.call())
assertEquals(Unit, Z(42U, 43)::x3.setter.call(42U))
assertEquals(1234UL, L::x1.call(L(1234UL, 5678L)))
assertEquals(5678L, L::x2.call(L(1234UL, 5678L)))
assertEquals(1234UL, L::x3.call(L(1234UL, 5678L)))
assertEquals(1234UL, L::x3.getter.call(L(1234UL, 5678L)))
assertEquals(Unit, L::x3.setter.call(L(1234UL, 5678L), 1234UL))
assertEquals(1234UL, L(1234UL, 5678L)::x1.call())
assertEquals(5678L, L(1234UL, 5678L)::x2.call())
assertEquals(1234UL, L(1234UL, 5678L)::x3.call())
assertEquals(1234UL, L(1234UL, 5678L)::x3.getter.call())
assertEquals(Unit, L(1234UL, 5678L)::x3.setter.call(1234UL))
assertEquals("abc", A1::x1.call(A1("abc", "def")))
assertEquals("def", A1::x2.call(A1("abc", "def")))
assertEquals("abc", A1::x3.call(A1("abc", "def")))
assertEquals("abc", A1::x3.getter.call(A1("abc", "def")))
assertEquals(Unit, A1::x3.setter.call(A1("abc", "def"), "abc"))
assertEquals("abc", A1("abc", "def")::x1.call())
assertEquals("def", A1("abc", "def")::x2.call())
assertEquals("abc", A1("abc", "def")::x3.call())
assertEquals("abc", A1("abc", "def")::x3.getter.call())
assertEquals(Unit, A1("abc", "def")::x3.setter.call("abc"))
assertEquals(null, A1::x1.call(A1(null, null)))
assertEquals(null, A1::x2.call(A1(null, null)))
assertEquals(null, A1::x3.call(A1(null, null)))
assertEquals(null, A1::x3.getter.call(A1(null, null)))
assertEquals(Unit, A1::x3.setter.call(A1(null, null), null))
assertEquals(null, A1(null, null)::x1.call())
assertEquals(null, A1(null, null)::x2.call())
assertEquals(null, A1(null, null)::x3.call())
assertEquals(null, A1(null, null)::x3.getter.call())
assertEquals(Unit, A1(null, null)::x3.setter.call(null))
assertEquals("abc", A2::x1.call(A2("abc", "def")))
assertEquals("def", A2::x2.call(A2("abc", "def")))
assertEquals("abc", A2::x3.call(A2("abc", "def")))
assertEquals("abc", A2::x3.getter.call(A2("abc", "def")))
assertEquals(Unit, A2::x3.setter.call(A2("abc", "def"), "abc"))
assertEquals("abc", A2("abc", "def")::x1.call())
assertEquals("def", A2("abc", "def")::x2.call())
assertEquals("abc", A2("abc", "def")::x3.call())
assertEquals("abc", A2("abc", "def")::x3.getter.call())
assertEquals(Unit, A2("abc", "def")::x3.setter.call("abc"))
assertEquals(Z(42U, 43), Z2::x1.call(Z2(Z(42U, 43), Z(44U, 45))))
assertEquals(Z(44U, 45), Z2::x2.call(Z2(Z(42U, 43), Z(44U, 45))))
assertEquals(Z(42U, 43), Z2::x3.call(Z2(Z(42U, 43), Z(44U, 45))))
assertEquals(Z(42U, 43), Z2::x3.getter.call(Z2(Z(42U, 43), Z(44U, 45))))
assertEquals(Unit, Z2::x3.setter.call(Z2(Z(42U, 43), Z(44U, 45)), Z(42U, 43)))
assertEquals(Z(42U, 43), Z2(Z(42U, 43), Z(44U, 45))::x1.call())
assertEquals(Z(44U, 45), Z2(Z(42U, 43), Z(44U, 45))::x2.call())
assertEquals(Z(42U, 43), Z2(Z(42U, 43), Z(44U, 45))::x3.call())
assertEquals(Z(42U, 43), Z2(Z(42U, 43), Z(44U, 45))::x3.getter.call())
assertEquals(Unit, Z2(Z(42U, 43), Z(44U, 45))::x3.setter.call(Z(42U, 43)))
assertEquals(L(1234UL, 5678L), L2::x1.call(L2(L(1234UL, 5678L), L(12340UL, -5678L))))
assertEquals(L(12340UL, -5678L), L2::x2.call(L2(L(1234UL, 5678L), L(12340UL, -5678L))))
assertEquals(L(1234UL, 5678L), L2::x3.call(L2(L(1234UL, 5678L), L(12340UL, -5678L))))
assertEquals(L(1234UL, 5678L), L2::x3.getter.call(L2(L(1234UL, 5678L), L(12340UL, -5678L))))
assertEquals(Unit, L2::x3.setter.call(L2(L(1234UL, 5678L), L(12340UL, -5678L)), L(1234UL, 5678L)))
assertEquals(L(1234UL, 5678L), L2(L(1234UL, 5678L), L(12340UL, -5678L))::x1.call())
assertEquals(L(12340UL, -5678L), L2(L(1234UL, 5678L), L(12340UL, -5678L))::x2.call())
assertEquals(L(1234UL, 5678L), L2(L(1234UL, 5678L), L(12340UL, -5678L))::x3.call())
assertEquals(L(1234UL, 5678L), L2(L(1234UL, 5678L), L(12340UL, -5678L))::x3.getter.call())
assertEquals(Unit, L2(L(1234UL, 5678L), L(12340UL, -5678L))::x3.setter.call(L(1234UL, 5678L)))
assertEquals(A1("abc", "def"), A1_2::x1.call(A1_2(A1("abc", "def"), A1("geh", "ijk"))))
assertEquals(A1("geh", "ijk"), A1_2::x2.call(A1_2(A1("abc", "def"), A1("geh", "ijk"))))
assertEquals(A1("abc", "def"), A1_2::x3.call(A1_2(A1("abc", "def"), A1("geh", "ijk"))))
assertEquals(A1("abc", "def"), A1_2::x3.getter.call(A1_2(A1("abc", "def"), A1("geh", "ijk"))))
assertEquals(Unit, A1_2::x3.setter.call(A1_2(A1("abc", "def"), A1("geh", "ijk")), A1("abc", "def")))
assertEquals(A1("abc", "def"), A1_2(A1("abc", "def"), A1("geh", "ijk"))::x1.call())
assertEquals(A1("geh", "ijk"), A1_2(A1("abc", "def"), A1("geh", "ijk"))::x2.call())
assertEquals(A1("abc", "def"), A1_2(A1("abc", "def"), A1("geh", "ijk"))::x3.call())
assertEquals(A1("abc", "def"), A1_2(A1("abc", "def"), A1("geh", "ijk"))::x3.getter.call())
assertEquals(Unit, A1_2(A1("abc", "def"), A1("geh", "ijk"))::x3.setter.call(A1("abc", "def")))
assertEquals(A1(null, null), A1_2::x1.call(A1_2(A1(null, null), A1(null, null))))
assertEquals(A1(null, null), A1_2::x2.call(A1_2(A1(null, null), A1(null, null))))
assertEquals(A1(null, null), A1_2::x3.call(A1_2(A1(null, null), A1(null, null))))
assertEquals(A1(null, null), A1_2::x3.getter.call(A1_2(A1(null, null), A1(null, null))))
assertEquals(Unit, A1_2::x3.setter.call(A1_2(A1(null, null), A1(null, null)), A1(null, null)))
assertEquals(A1(null, null), A1_2(A1(null, null), A1(null, null))::x1.call())
assertEquals(A1(null, null), A1_2(A1(null, null), A1(null, null))::x2.call())
assertEquals(A1(null, null), A1_2(A1(null, null), A1(null, null))::x3.call())
assertEquals(A1(null, null), A1_2(A1(null, null), A1(null, null))::x3.getter.call())
assertEquals(Unit, A1_2(A1(null, null), A1(null, null))::x3.setter.call(A1(null, null)))
assertEquals(A2("abc", "def"), A2_2::x1.call(A2_2(A2("abc", "def"), A2("geh", "ijk"))))
assertEquals(A2("geh", "ijk"), A2_2::x2.call(A2_2(A2("abc", "def"), A2("geh", "ijk"))))
assertEquals(A2("abc", "def"), A2_2::x3.call(A2_2(A2("abc", "def"), A2("geh", "ijk"))))
assertEquals(A2("abc", "def"), A2_2::x3.getter.call(A2_2(A2("abc", "def"), A2("geh", "ijk"))))
assertEquals(Unit, A2_2::x3.setter.call(A2_2(A2("abc", "def"), A2("geh", "ijk")), A2("abc", "def")))
assertEquals(A2("abc", "def"), A2_2(A2("abc", "def"), A2("geh", "ijk"))::x1.call())
assertEquals(A2("geh", "ijk"), A2_2(A2("abc", "def"), A2("geh", "ijk"))::x2.call())
assertEquals(A2("abc", "def"), A2_2(A2("abc", "def"), A2("geh", "ijk"))::x3.call())
assertEquals(A2("abc", "def"), A2_2(A2("abc", "def"), A2("geh", "ijk"))::x3.getter.call())
assertEquals(Unit, A2_2(A2("abc", "def"), A2("geh", "ijk"))::x3.setter.call(A2("abc", "def")))
return "OK"
}
@@ -0,0 +1,122 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.reflect.KMutableProperty2
import kotlin.test.assertEquals
@JvmInline
value class Z(val value1: UInt, val value2: Int) {
operator fun plus(other: Z): Z = Z(this.value1 + other.value1, this.value2 + other.value2)
}
class C {
var nonNullMember: Z = Z(0U, 0)
var nullableMember: Z? = Z(0U, 0)
private var offset = Z(0U, 0)
var Z.nonNull_nonNullMemExt: Z
get() = this + offset
set(value) { offset = this + value }
var Z.nonNull_nullableMemExt: Z?
get() = this + offset
set(value) { offset = this + value!! }
var Z?.nullable_nonNullMemExt: Z
get() = this!! + offset
set(value) { offset = this!! + value }
var Z?.nullable_nullableMemExt: Z?
get() = this!! + offset
set(value) { offset = this!! + value!! }
}
var nonNullTopLevel: Z = Z(0U, 0)
var nullableTopLevel: Z? = Z(0U, 0)
private var offset = Z(0U, 0)
var Z.nonNull_nonNullExt: Z
get() = this + offset
set(value) { offset = this + value }
var Z.nonNull_nullableExt: Z?
get() = this + offset
set(value) { offset = this + value!! }
var Z?.nullable_nonNullExt: Z
get() = this!! + offset
set(value) { offset = this!! + value }
var Z?.nullable_nullableExt: Z?
get() = this!! + offset
set(value) { offset = this!! + value!! }
fun box(): String {
val one = Z(1U, -1)
val two = Z(2U, -2)
val three = Z(3U, -3)
val c = C()
assertEquals(Unit, C::nonNullMember.setter.call(c, one))
assertEquals(one, C::nonNullMember.call(c))
assertEquals(one, C::nonNullMember.getter.call(c))
assertEquals(Unit, c::nonNullMember.setter.call(two))
assertEquals(two, c::nonNullMember.call())
assertEquals(two, c::nonNullMember.getter.call())
assertEquals(Unit, C::nullableMember.setter.call(c, one))
assertEquals(one, C::nullableMember.call(c))
assertEquals(one, C::nullableMember.getter.call(c))
assertEquals(Unit, c::nullableMember.setter.call(two))
assertEquals(two, c::nullableMember.call())
assertEquals(two, c::nullableMember.getter.call())
val nonNull_nonNullMemExt = C::class.members.single { it.name == "nonNull_nonNullMemExt" } as KMutableProperty2<C, Z, Z>
assertEquals(Unit, nonNull_nonNullMemExt.setter.call(c, Z(0U, 0), two))
assertEquals(three, nonNull_nonNullMemExt.call(c, one))
assertEquals(three, nonNull_nonNullMemExt.getter.call(c, one))
val nonNull_nullableMemExt = C::class.members.single { it.name == "nonNull_nullableMemExt" } as KMutableProperty2<C, Z, Z?>
assertEquals(Unit, nonNull_nullableMemExt.setter.call(c, Z(0U, 0), two))
assertEquals(three, nonNull_nullableMemExt.call(c, one))
assertEquals(three, nonNull_nullableMemExt.getter.call(c, one))
val nullable_nonNullMemExt = C::class.members.single { it.name == "nullable_nonNullMemExt" } as KMutableProperty2<C, Z?, Z>
assertEquals(Unit, nullable_nonNullMemExt.setter.call(c, Z(0U, 0), two))
assertEquals(three, nullable_nonNullMemExt.call(c, one))
assertEquals(three, nullable_nonNullMemExt.getter.call(c, one))
val nullable_nullableMemExt = C::class.members.single { it.name == "nullable_nullableMemExt" } as KMutableProperty2<C, Z?, Z?>
assertEquals(Unit, nullable_nullableMemExt.setter.call(c, Z(0U, 0), two))
assertEquals(three, nullable_nullableMemExt.call(c, one))
assertEquals(three, nullable_nullableMemExt.getter.call(c, one))
assertEquals(Unit, ::nonNullTopLevel.setter.call(one))
assertEquals(one, ::nonNullTopLevel.call())
assertEquals(one, ::nonNullTopLevel.getter.call())
assertEquals(Unit, ::nullableTopLevel.setter.call(one))
assertEquals(one, ::nullableTopLevel.call())
assertEquals(one, ::nullableTopLevel.getter.call())
assertEquals(Unit, Z::nonNull_nonNullExt.setter.call(Z(0U, 0), two))
assertEquals(three, Z::nonNull_nonNullExt.call(one))
assertEquals(three, Z::nonNull_nonNullExt.getter.call(one))
assertEquals(Unit, Z::nonNull_nullableExt.setter.call(Z(0U, 0), two))
assertEquals(three, Z::nonNull_nullableExt.call(one))
assertEquals(three, Z::nonNull_nullableExt.getter.call(one))
assertEquals(Unit, Z?::nullable_nonNullExt.setter.call(Z(0U, 0), two))
assertEquals(three, Z?::nullable_nonNullExt.call(one))
assertEquals(three, Z?::nullable_nonNullExt.getter.call(one))
assertEquals(Unit, Z?::nullable_nullableExt.setter.call(Z(0U, 0), two))
assertEquals(three, Z?::nullable_nullableExt.call(one))
assertEquals(three, Z?::nullable_nullableExt.getter.call(one))
return "OK"
}
@@ -0,0 +1,91 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// WITH_COROUTINES
// LANGUAGE: +ValueClasses
import kotlin.coroutines.startCoroutine
import kotlin.reflect.full.callSuspend
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import helpers.*
@JvmInline
value class Z(val value1: UInt, val value2: Int)
class C {
private var value: Z = Z(0U, 0)
suspend fun nonNullConsume(z: Z) { value = z }
suspend fun nonNullProduce(): Z = value
suspend fun nullableConsume(z: Z?) { value = z!! }
suspend fun nullableProduce(): Z? = value
suspend fun nonNull_nonNullConsumeAndProduce(z: Z): Z = z
suspend fun nonNull_nullableConsumeAndProduce(z: Z): Z? = z
suspend fun nullable_nonNullConsumeAndProduce(z: Z?): Z = z!!
suspend fun nullable_nullableConsumeAndProduce(z: Z?): Z? = z
}
private fun run0(f: suspend () -> Int): Int {
var result = -1
f.startCoroutine(handleResultContinuation { result = it })
return result
}
private fun run0U(f: suspend () -> UInt): UInt {
var result = UInt.MAX_VALUE
f.startCoroutine(handleResultContinuation { result = it })
return result
}
fun box(): String {
val c = C()
run0U {
C::nonNullConsume.callSuspend(c, Z(1U, -1))
C::nonNullProduce.callSuspend(c).value1
}.let { assertEquals(1U, it) }
run0 {
C::nonNullConsume.callSuspend(c, Z(1U, -1))
C::nonNullProduce.callSuspend(c).value2
}.let { assertEquals(-1, it) }
run0U {
C::nullableConsume.callSuspend(c, Z(2U, -2))
C::nullableProduce.callSuspend(c)!!.value1
}.let { assertEquals(2U, it) }
run0 {
C::nullableConsume.callSuspend(c, Z(2U, -2))
C::nullableProduce.callSuspend(c)!!.value2
}.let { assertEquals(-2, it) }
run0U {
C::nonNull_nonNullConsumeAndProduce.callSuspend(c, Z(3U, -3)).value1
}.let { assertEquals(3U, it) }
run0 {
C::nonNull_nonNullConsumeAndProduce.callSuspend(c, Z(3U, -3)).value2
}.let { assertEquals(-3, it) }
run0U {
C::nonNull_nullableConsumeAndProduce.callSuspend(c, Z(4U, -4))!!.value1
}.let { assertEquals(4U, it) }
run0 {
C::nonNull_nullableConsumeAndProduce.callSuspend(c, Z(4U, -4))!!.value2
}.let { assertEquals(-4, it) }
run0U {
C::nullable_nonNullConsumeAndProduce.callSuspend(c, Z(5U, -5)).value1
}.let { assertEquals(5U, it) }
run0 {
C::nullable_nonNullConsumeAndProduce.callSuspend(c, Z(5U, -5)).value2
}.let { assertEquals(-5, it) }
run0U {
C::nullable_nullableConsumeAndProduce.callSuspend(c, Z(6U, -6))!!.value1
}.let { assertEquals(6U, it) }
run0 {
C::nullable_nullableConsumeAndProduce.callSuspend(c, Z(6U, -6))!!.value2
}.let { assertEquals(-6, it) }
return "OK"
}
@@ -0,0 +1,72 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.test.assertEquals
@JvmInline
value class A(val x: UInt, val y: Int)
fun test1(x: A = A(0U, 1)) = "OK"
fun test32(
arg00: Long = 0L, arg01: Long = 0L, arg02: Long = 0L, arg03: Long = 0L, arg04: Long = 0L,
arg05: Long = 0L, arg06: Long = 0L, arg07: Long = 0L, arg08: Long = 0L, arg09: Long = 0L,
arg10: Long = 0L, arg11: Long = 0L, arg12: Long = 0L, arg13: Long = 0L, arg14: Long = 0L,
arg15: Long = 0L, arg16: Long = 0L, arg17: Long = 0L, arg18: Long = 0L, arg19: Long = 0L,
arg20: Long = 0L, arg21: Long = 0L, arg22: Long = 0L, arg23: Long = 0L, arg24: Long = 0L,
arg25: Long = 0L, arg26: Long = 0L, arg27: Long = 0L, arg28: Long = 0L, arg29: Long = 0L,
arg30: Long = 0L, x: A = A(0U, 1)
) = "OK"
fun test33(
arg00: Long = 0L, arg01: Long = 0L, arg02: Long = 0L, arg03: Long = 0L, arg04: Long = 0L,
arg05: Long = 0L, arg06: Long = 0L, arg07: Long = 0L, arg08: Long = 0L, arg09: Long = 0L,
arg10: Long = 0L, arg11: Long = 0L, arg12: Long = 0L, arg13: Long = 0L, arg14: Long = 0L,
arg15: Long = 0L, arg16: Long = 0L, arg17: Long = 0L, arg18: Long = 0L, arg19: Long = 0L,
arg20: Long = 0L, arg21: Long = 0L, arg22: Long = 0L, arg23: Long = 0L, arg24: Long = 0L,
arg25: Long = 0L, arg26: Long = 0L, arg27: Long = 0L, arg28: Long = 0L, arg29: Long = 0L,
arg30: Long = 0L, arg31: Long = 0L, x: A = A(0U, 1)
) = "OK"
fun test64(
arg00: Long = 0L, arg01: Long = 0L, arg02: Long = 0L, arg03: Long = 0L, arg04: Long = 0L,
arg05: Long = 0L, arg06: Long = 0L, arg07: Long = 0L, arg08: Long = 0L, arg09: Long = 0L,
arg10: Long = 0L, arg11: Long = 0L, arg12: Long = 0L, arg13: Long = 0L, arg14: Long = 0L,
arg15: Long = 0L, arg16: Long = 0L, arg17: Long = 0L, arg18: Long = 0L, arg19: Long = 0L,
arg20: Long = 0L, arg21: Long = 0L, arg22: Long = 0L, arg23: Long = 0L, arg24: Long = 0L,
arg25: Long = 0L, arg26: Long = 0L, arg27: Long = 0L, arg28: Long = 0L, arg29: Long = 0L,
arg30: Long = 0L, arg31: Long = 0L, arg32: Long = 0L, arg33: Long = 0L, arg34: Long = 0L,
arg35: Long = 0L, arg36: Long = 0L, arg37: Long = 0L, arg38: Long = 0L, arg39: Long = 0L,
arg40: Long = 0L, arg41: Long = 0L, arg42: Long = 0L, arg43: Long = 0L, arg44: Long = 0L,
arg45: Long = 0L, arg46: Long = 0L, arg47: Long = 0L, arg48: Long = 0L, arg49: Long = 0L,
arg50: Long = 0L, arg51: Long = 0L, arg52: Long = 0L, arg53: Long = 0L, arg54: Long = 0L,
arg55: Long = 0L, arg56: Long = 0L, arg57: Long = 0L, arg58: Long = 0L, arg59: Long = 0L,
arg60: Long = 0L, arg61: Long = 0L, arg62: Long = 0L, x: A = A(0U, 1)
) = "OK"
fun test65(
arg00: Long = 0L, arg01: Long = 0L, arg02: Long = 0L, arg03: Long = 0L, arg04: Long = 0L,
arg05: Long = 0L, arg06: Long = 0L, arg07: Long = 0L, arg08: Long = 0L, arg09: Long = 0L,
arg10: Long = 0L, arg11: Long = 0L, arg12: Long = 0L, arg13: Long = 0L, arg14: Long = 0L,
arg15: Long = 0L, arg16: Long = 0L, arg17: Long = 0L, arg18: Long = 0L, arg19: Long = 0L,
arg20: Long = 0L, arg21: Long = 0L, arg22: Long = 0L, arg23: Long = 0L, arg24: Long = 0L,
arg25: Long = 0L, arg26: Long = 0L, arg27: Long = 0L, arg28: Long = 0L, arg29: Long = 0L,
arg30: Long = 0L, arg31: Long = 0L, arg32: Long = 0L, arg33: Long = 0L, arg34: Long = 0L,
arg35: Long = 0L, arg36: Long = 0L, arg37: Long = 0L, arg38: Long = 0L, arg39: Long = 0L,
arg40: Long = 0L, arg41: Long = 0L, arg42: Long = 0L, arg43: Long = 0L, arg44: Long = 0L,
arg45: Long = 0L, arg46: Long = 0L, arg47: Long = 0L, arg48: Long = 0L, arg49: Long = 0L,
arg50: Long = 0L, arg51: Long = 0L, arg52: Long = 0L, arg53: Long = 0L, arg54: Long = 0L,
arg55: Long = 0L, arg56: Long = 0L, arg57: Long = 0L, arg58: Long = 0L, arg59: Long = 0L,
arg60: Long = 0L, arg61: Long = 0L, arg62: Long = 0L, arg63: Long = 0L, x: A = A(0U, 1)
) = "OK"
fun box(): String {
assertEquals("OK", ::test1.callBy(mapOf()))
assertEquals("OK", ::test32.callBy(mapOf()))
assertEquals("OK", ::test33.callBy(mapOf()))
assertEquals("OK", ::test64.callBy(mapOf()))
assertEquals("OK", ::test65.callBy(mapOf()))
return "OK"
}
@@ -0,0 +1,53 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.test.assertEquals
import kotlin.test.assertTrue
@JvmInline
value class S(val value1: UInt, val value2: String) {
operator fun plus(other: S): S = S(this.value1 * 10U + other.value1, this.value2 + other.value2)
}
class C {
fun member(a: S, b: S = S(1U, "b2")): S = a + b
}
fun topLevel(c: S, d: S = S(1U, "d2")): S = c + d
class D(e: S, f: S = S(1U, "f2")) {
val result = e + f
}
fun S.extension(h: S = S(1U, "h2")): S = this + h
fun box(): String {
assertEquals(S(11U, "a2b2"), C().member(S(1U, "a2")))
assertEquals(
S(11U, "a2b2"),
C::member.callBy(C::member.parameters.filter { it.name != "b" }.associateWith { (if (it.name == "a") S(1U, "a2") else C()) })
)
assertEquals(S(11U, "c2d2"), topLevel(S(1U, "c2")))
assertEquals(S(11U, "c2d2"), ::topLevel.callBy(::topLevel.parameters.filter { it.name != "d" }.associateWith { S(1U, "c2") }))
assertEquals(S(11U, "e2f2"), ::D.callBy(::D.parameters.filter { it.name != "f" }.associateWith { S(1U, "e2") }).result)
assertEquals(S(11U, "g2h2"), S(1U, "g2").extension())
assertEquals(S(11U, "g2h2"), S::extension.callBy(S::extension.parameters.filter { it.name != "h" }.associateWith { S(1U, "g2") }))
val boundMember = C()::member
assertEquals(S(11U, "a2b2"), boundMember.callBy(boundMember.parameters.associateWith { S(1U, it.name!! + "2") }))
val boundExtension = S(1U, "g2")::extension
assertEquals(S(11U, "g2h2"), boundExtension.callBy(boundExtension.parameters.associateWith { S(1U, it.name!! + "2") }))
val mfvcConstructor = ::S
val exception = runCatching { mfvcConstructor.callBy(mapOf(mfvcConstructor.parameters.first() to 1U)) }.exceptionOrNull()!!
assertTrue(exception is IllegalArgumentException)
assertTrue(exception.message!!.startsWith("No argument provided for a required parameter: parameter #1 value2 of fun `<init>`(kotlin.UInt, kotlin.String): "), exception.message)
assertTrue(exception.message!!.endsWith("S"), exception.message)
return "OK"
}
@@ -0,0 +1,77 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.test.assertEquals
interface IFoo {
fun fooFun(z: Z): Z
var fooVar: Z
}
var global = Z(0U, 0)
@JvmInline
value class Z(val x1: UInt, val x2: Int) : IFoo {
override fun fooFun(z: Z): Z = Z(z.x1 + x1, z.x2 + x2)
override var fooVar: Z
get() = Z(global.x1 + x1, global.x2 + x2)
set(value) {
global = Z(value.x1 + x1, value.x2 + x2)
}
fun barFun(z: Z): Z = Z(z.x1 * 100U + x1, z.x2 * 100 + x2)
var barVar: Z
get() = Z(global.x1 * 100U + x1, global.x2 * 100 + x2)
set(value) {
global = Z(value.x1 * 100U + x1, value.x2 * 100 + x2)
}
}
fun box(): String {
val fooFunR = Z::fooFun
assertEquals(Z(53U, -53), fooFunR.callBy(mapOf(fooFunR.parameters[0] to Z(42U, -42), fooFunR.parameters[1] to Z(11U, -11))))
val fooFunBR = Z(42U, -42)::fooFun
assertEquals(Z(142U, -142), fooFunBR.callBy(mapOf(fooFunBR.parameters[0] to Z(100U, -100))))
global = Z(0U, 0)
val fooVarR = Z::fooVar
assertEquals(Z(42U, -42), fooVarR.callBy(mapOf(fooVarR.parameters[0] to Z(42U, -42))))
assertEquals(Z(42U, -42), fooVarR.getter.callBy(mapOf(fooVarR.getter.parameters[0] to Z(42U, -42))))
fooVarR.setter.callBy(mapOf(fooVarR.setter.parameters[0] to Z(42U, -42), fooVarR.setter.parameters[1] to Z(1U, -1)))
assertEquals(Z(43U, -43), global)
global = Z(100U, -100)
val fooVarBR = Z(42U, -42)::fooVar
assertEquals(Z(142U, -142), fooVarBR.callBy(mapOf()))
assertEquals(Z(142U, -142), fooVarBR.getter.callBy(mapOf()))
fooVarBR.setter.callBy(mapOf(fooVarBR.setter.parameters[0] to Z(1U, -1)))
assertEquals(Z(43U, -43), global)
val barFunR = Z::barFun
assertEquals(Z(1142U, -1142), barFunR.callBy(mapOf(barFunR.parameters[0] to Z(42U, -42), barFunR.parameters[1] to Z(11U, -11))))
val barFunBR = Z(42U, -42)::barFun
assertEquals(Z(2242U, -2242), barFunBR.callBy(mapOf(barFunBR.parameters[0] to Z(22U, -22))))
global = Z(1U, -1)
val barVarR = Z::barVar
assertEquals(Z(142U, -142), barVarR.callBy(mapOf(barVarR.parameters[0] to Z(42U, -42))))
assertEquals(Z(142U, -142), barVarR.getter.callBy(mapOf(barVarR.getter.parameters[0] to Z(42U, -42))))
barVarR.setter.callBy(mapOf(barVarR.setter.parameters[0] to Z(42U, -42), barVarR.setter.parameters[1] to Z(3U, -3)))
assertEquals(Z(342U, -342), global)
global = Z(2U, -2)
val barVarBR = Z(42U, -42)::barVar
assertEquals(Z(242U, -242), barVarBR.callBy(mapOf()))
assertEquals(Z(242U, -242), barVarBR.getter.callBy(mapOf()))
barVarBR.setter.callBy(mapOf(barVarBR.setter.parameters[0] to Z(4U, -4)))
assertEquals(Z(442U, -442), global)
return "OK"
}
@@ -0,0 +1,14 @@
// LAMBDAS: CLASS
// !OPT_IN: kotlin.reflect.jvm.ExperimentalReflectionOnLambdas
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.reflect.jvm.reflect
@JvmInline
value class C(val x1: UInt, val x2: Int)
fun C.f(x: (String) -> Unit = { OK: String -> }) = x.reflect()?.parameters?.singleOrNull()?.name
fun box(): String = C(0U, 1).f() ?: "null"
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.reflect.full.primaryConstructor
import kotlin.reflect.jvm.javaConstructor
import kotlin.reflect.jvm.kotlinFunction
import kotlin.test.assertEquals
@JvmInline
value class Z(val x1: UInt, val x2: Int)
class Test(val x: Z)
fun box(): String {
val kctor1 = Test::class.primaryConstructor ?: throw AssertionError("No primary constructor")
val jctor1 = kctor1.javaConstructor ?: throw AssertionError("No javaConstructor for $kctor1")
val kctor2 = jctor1.kotlinFunction ?: throw AssertionError("No kotlinFunction for $jctor1")
assertEquals(kctor1, kctor2)
assertEquals("[x]", kctor2.parameters.map { it.name }.toString())
return "OK"
}
@@ -8,20 +8,16 @@ inline class S(val value: String)
fun S.foo(x: Int, s: S): S = this
/* TODO: Support calling members of inline classes in reflection (KT-26748)
inline class T(val s: S) {
fun bar(u: S): T = this
}
*/
fun box(): String {
assertEquals(listOf(String::class.java, Int::class.java, String::class.java), S::foo.parameters.map { it.type.javaType })
assertEquals(String::class.java, S::foo.returnType.javaType)
/*
assertEquals(listOf(), T::bar.parameters.map { it.type.javaType })
assertEquals(listOf(String::class.java, String::class.java), T::bar.parameters.map { it.type.javaType })
assertEquals(String::class.java, T::bar.returnType.javaType)
*/
return "OK"
}
@@ -0,0 +1,46 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.reflect.jvm.*
import kotlin.test.assertEquals
import java.lang.reflect.Type
@JvmInline
value class S(val value1: UInt, val value2: String)
fun S.foo(x: Int, s: S): S = this
fun compoundType(vararg types: Type) = listOf(*types).toString()
@JvmInline
value class T(val s: S) {
fun bar(u: S): T = this
}
data class U(val s: S) {
fun bar(u: S): U = this
}
@kotlin.ExperimentalStdlibApi
fun box(): String {
assertEquals(listOf(Int::class.java, String::class.java), ::S.parameters.map { it.type.javaType })
assertEquals(S::class.java, ::S.returnType.javaType)
assertEquals(listOf(compoundType(Int::class.java, String::class.java)), ::T.parameters.map { it.type.javaType.toString() })
assertEquals(T::class.java, ::T.returnType.javaType)
assertEquals(listOf(compoundType(Int::class.java, String::class.java)), ::U.parameters.map { it.type.javaType.toString() })
assertEquals(U::class.java, ::U.returnType.javaType)
assertEquals(listOf(compoundType(Int::class.java, String::class.java), Int::class.java.toString(), compoundType(Int::class.java, String::class.java)), S::foo.parameters.map { it.type.javaType.toString() })
assertEquals(S::class.java, S::foo.returnType.javaType)
assertEquals(listOf(compoundType(Int::class.java, String::class.java), compoundType(Int::class.java, String::class.java)), T::bar.parameters.map { it.type.javaType.toString() })
assertEquals(T::class.java, T::bar.returnType.javaType)
assertEquals(listOf(U::class.java.toString(), compoundType(Int::class.java, String::class.java)), U::bar.parameters.map { it.type.javaType.toString() })
assertEquals(U::class.java, U::bar.returnType.javaType)
return "OK"
}
@@ -0,0 +1,85 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
package test
import kotlin.reflect.KCallable
import kotlin.reflect.jvm.*
import kotlin.test.assertEquals
@JvmInline
value class Z1(val publicX1: UInt, val publicX2: Int) {
companion object {
val publicX1Ref = Z1::publicX1
val publicX2Ref = Z1::publicX2
val publicX1BoundRef = Z1(42U, 43)::publicX1
val publicX2BoundRef = Z1(42U, 43)::publicX2
}
}
@JvmInline
value class Z2(internal val internalX1: UInt, internal val internalX2: Int) {
companion object {
val internalX1Ref = Z2::internalX1
val internalX2Ref = Z2::internalX2
val internalX1BoundRef = Z2(42U, 43)::internalX1
val internalX2BoundRef = Z2(42U, 43)::internalX2
}
}
@JvmInline
value class Z3(private val privateX1: UInt, private val privateX2: Int) {
companion object {
val privateX1Ref = Z3::privateX1
val privateX2Ref = Z3::privateX2
val privateX1BoundRef = Z3(42U, 43)::privateX1
val privateX2BoundRef = Z3(42U, 43)::privateX2
}
}
@JvmInline
value class ZZ(val x1: Z1, val x2: Z1)
fun KCallable<*>.getJavaTypesOfParams() = parameters.map { it.type.javaType }.toString()
fun KCallable<*>.getJavaTypeOfResult() = returnType.javaType.toString()
fun box(): String {
assertEquals("[class test.Z1]", Z1.publicX1Ref.getJavaTypesOfParams())
assertEquals("[class test.Z1]", Z1.publicX2Ref.getJavaTypesOfParams())
assertEquals("int", Z1.publicX1Ref.getJavaTypeOfResult())
assertEquals("int", Z1.publicX2Ref.getJavaTypeOfResult())
assertEquals("[]", Z1.publicX1BoundRef.getJavaTypesOfParams())
assertEquals("[]", Z1.publicX2BoundRef.getJavaTypesOfParams())
assertEquals("int", Z1.publicX1BoundRef.getJavaTypeOfResult())
assertEquals("int", Z1.publicX2BoundRef.getJavaTypeOfResult())
assertEquals("[class test.Z2]", Z2.internalX1Ref.getJavaTypesOfParams())
assertEquals("[class test.Z2]", Z2.internalX2Ref.getJavaTypesOfParams())
assertEquals("int", Z2.internalX1Ref.getJavaTypeOfResult())
assertEquals("int", Z2.internalX2Ref.getJavaTypeOfResult())
assertEquals("[]", Z2.internalX1BoundRef.getJavaTypesOfParams())
assertEquals("[]", Z2.internalX2BoundRef.getJavaTypesOfParams())
assertEquals("int", Z2.internalX1BoundRef.getJavaTypeOfResult())
assertEquals("int", Z2.internalX2BoundRef.getJavaTypeOfResult())
assertEquals("[class test.Z3]", Z3.privateX1Ref.getJavaTypesOfParams())
assertEquals("[class test.Z3]", Z3.privateX2Ref.getJavaTypesOfParams())
assertEquals("int", Z3.privateX1Ref.getJavaTypeOfResult())
assertEquals("int", Z3.privateX2Ref.getJavaTypeOfResult())
assertEquals("[]", Z3.privateX1BoundRef.getJavaTypesOfParams())
assertEquals("[]", Z3.privateX2BoundRef.getJavaTypesOfParams())
assertEquals("int", Z3.privateX1BoundRef.getJavaTypeOfResult())
assertEquals("int", Z3.privateX2BoundRef.getJavaTypeOfResult())
assertEquals("[class test.ZZ]", ZZ::x1.getJavaTypesOfParams())
assertEquals("[class test.ZZ]", ZZ::x2.getJavaTypesOfParams())
assertEquals("class test.Z1", ZZ::x1.getJavaTypeOfResult())
assertEquals("class test.Z1", ZZ::x2.getJavaTypeOfResult())
return "OK"
}
@@ -0,0 +1,90 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
import kotlin.reflect.jvm.*
import kotlin.test.assertEquals
import kotlin.test.assertTrue
@JvmInline
value class Z1(val publicX1: UInt, val publicX2: Int) {
companion object {
val publicX1Ref = Z1::publicX1
val publicX2Ref = Z1::publicX2
val publicX1BoundRef = Z1(42U, -42)::publicX1
val publicX2BoundRef = Z1(42U, -42)::publicX2
}
}
@JvmInline
value class Z2(internal val internalX1: UInt, internal val internalX2: Int) {
companion object {
val internalX1Ref = Z2::internalX1
val internalX2Ref = Z2::internalX2
val internalX1BoundRef = Z2(42U, -42)::internalX1
val internalX2BoundRef = Z2(42U, -42)::internalX2
}
}
@JvmInline
value class Z3(private val privateX1: UInt, private val privateX2: Int) {
companion object {
val privateX1Ref = Z3::privateX1
val privateX2Ref = Z3::privateX2
val privateX1BoundRef = Z3(42U, -42)::privateX1
val privateX2BoundRef = Z3(42U, -42)::privateX2
}
}
@JvmInline
value class Z1_2(val publicX: Z1) {
companion object {
val publicXRef = Z1_2::publicX
val publicXBoundRef = Z1_2(Z1(42U, -42))::publicX
}
}
@JvmInline
value class Z2_2(internal val internalX: Z2) {
companion object {
val internalXRef = Z2_2::internalX
val internalXBoundRef = Z2_2(Z2(42U, -42))::internalX
}
}
@JvmInline
value class Z3_2(private val privateX: Z3) {
companion object {
val privateXRef = Z3_2::privateX
val privateXBoundRef = Z3_2(Z3(42U, -42))::privateX
}
}
fun box(): String {
val suffix = "-pVg5ArA"
assertEquals("getPublicX1$suffix", Z1.publicX1Ref.javaGetter!!.name)
assertEquals("getPublicX2", Z1.publicX2Ref.javaGetter!!.name)
assertEquals("getPublicX1$suffix", Z1.publicX1BoundRef.javaGetter!!.name)
assertEquals("getPublicX2", Z1.publicX2BoundRef.javaGetter!!.name)
assertTrue(Z2.internalX1Ref.javaGetter!!.name.startsWith("getInternalX1$suffix\$"), Z2.internalX1Ref.javaGetter!!.name)
assertTrue(Z2.internalX2Ref.javaGetter!!.name.startsWith("getInternalX2\$"), Z2.internalX2Ref.javaGetter!!.name)
assertTrue(Z2.internalX1BoundRef.javaGetter!!.name.startsWith("getInternalX1$suffix\$"), Z2.internalX1BoundRef.javaGetter!!.name)
assertTrue(Z2.internalX2BoundRef.javaGetter!!.name.startsWith("getInternalX2\$"), Z2.internalX2BoundRef.javaGetter!!.name)
assertEquals(null, Z3.privateX1Ref.javaGetter)
assertEquals(null, Z3.privateX2Ref.javaGetter)
assertEquals(null, Z3.privateX1BoundRef.javaGetter)
assertEquals(null, Z3.privateX2BoundRef.javaGetter)
assertEquals("getPublicX", Z1_2.publicXRef.javaGetter!!.name)
assertEquals("getPublicX", Z1_2.publicXBoundRef.javaGetter!!.name)
assertTrue(Z2_2.internalXRef.javaGetter!!.name.startsWith("getInternalX\$"), Z2_2.internalXRef.javaGetter!!.name)
assertTrue(Z2_2.internalXBoundRef.javaGetter!!.name.startsWith("getInternalX\$"), Z2_2.internalXBoundRef.javaGetter!!.name)
assertEquals("getPrivateX", Z3_2.privateXRef.javaGetter!!.name)
assertEquals("getPrivateX", Z3_2.privateXBoundRef.javaGetter!!.name)
return "OK"
}
@@ -0,0 +1,49 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
package test
import kotlin.reflect.*
import kotlin.reflect.jvm.*
import kotlin.test.assertEquals
import kotlin.test.assertTrue
@JvmInline
value class Z(val value1: UInt, val value2: String)
class S {
suspend fun consumeZ(z: Z) {}
suspend fun produceZ(): Z = Z(0U, "")
suspend fun consumeAndProduceZ(z: Z): Z = z
}
fun box(): String {
val members = S::class.members.filterIsInstance<KFunction<*>>().associateBy(KFunction<*>::name)
members["consumeZ"]!!.let { cz ->
val czj = cz.javaMethod!!
assertTrue(czj.name.startsWith("consumeZ-"), czj.name)
assertEquals("int, java.lang.String, kotlin.coroutines.Continuation", czj.parameterTypes.joinToString { it.name })
val czjk = czj.kotlinFunction
assertEquals(cz, czjk)
}
members["produceZ"]!!.let { pz ->
val pzj = pz.javaMethod!!
assertEquals("produceZ", pzj.name)
assertEquals("kotlin.coroutines.Continuation", pzj.parameterTypes.joinToString { it.name })
val pzjk = pzj!!.kotlinFunction
assertEquals(pz, pzjk)
}
members["consumeAndProduceZ"]!!.let { cpz ->
val cpzj = cpz.javaMethod!!
assertTrue(cpzj.name.startsWith("consumeAndProduceZ-"), cpzj.name)
assertEquals("int, java.lang.String, kotlin.coroutines.Continuation", cpzj.parameterTypes.joinToString { it.name })
val cpzjk = cpzj!!.kotlinFunction
assertEquals(cpz, cpzjk)
}
return "OK"
}
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
// FILE: box.kt
import kotlin.test.assertTrue
import kotlin.test.assertFalse
@JvmInline
value class V(val value: String, val value1: String)
fun box(): String {
assertFalse(V::class.isSealed)
assertFalse(V::class.isData)
assertFalse(V::class.isInner)
assertFalse(V::class.isCompanion)
assertFalse(V::class.isFun)
assertTrue(V::class.isValue)
return "OK"
}
+25
View File
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM_IR
// WITH_REFLECT
// LANGUAGE: +ValueClasses
package test
import kotlin.reflect.KType
import kotlin.reflect.typeOf
import kotlin.test.assertEquals
@JvmInline
value class Z(val value1: String, val value2: String)
fun check(expected: String, actual: KType) {
assertEquals(expected, actual.toString())
}
fun box(): String {
check("test.Z", typeOf<Z>())
check("test.Z?", typeOf<Z?>())
check("kotlin.Array<test.Z>", typeOf<Array<Z>>())
check("kotlin.Array<test.Z?>", typeOf<Array<Z?>>())
return "OK"
}
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM_IR
// WITH_STDLIB
// LANGUAGE: +ValueClasses
package test
import kotlin.reflect.KType
import kotlin.reflect.typeOf
import kotlin.test.assertEquals
@JvmInline
value class Z(val value1: String, val value2: String)
fun check(expected: String, actual: KType) {
assertEquals(expected + " (Kotlin reflection is not available)", actual.toString())
}
fun box(): String {
check("test.Z", typeOf<Z>())
check("test.Z?", typeOf<Z?>())
check("kotlin.Array<test.Z>", typeOf<Array<Z>>())
check("kotlin.Array<test.Z?>", typeOf<Array<Z?>>())
return "OK"
}