Add tests for KFunction involving value classes
See KT-31141.
This commit is contained in:
committed by
Alexander Udalov
parent
c8453ec8b4
commit
c4735f9f29
+59
@@ -0,0 +1,59 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
inline class Z(val x: Int)
|
||||
|
||||
class Outer(val z1: Z, val z2: Z?) {
|
||||
inner class Inner(val z3: Z, val z4: Z?) {
|
||||
val test = "$z1 $z2 $z3 $z4"
|
||||
}
|
||||
}
|
||||
|
||||
inline class InlineNonNullOuter(val z1: Z) {
|
||||
@Suppress("INNER_CLASS_INSIDE_VALUE_CLASS")
|
||||
inner class Inner(val z2: Z, val z3: Z?) {
|
||||
val test = "$z1 $z2 $z3"
|
||||
}
|
||||
}
|
||||
|
||||
inline class InlineNullableOuter(val z1: Z?) {
|
||||
@Suppress("INNER_CLASS_INSIDE_VALUE_CLASS")
|
||||
inner class Inner(val z2: Z, val z3: Z?) {
|
||||
val test = "$z1 $z2 $z3"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val z1 = Z(1)
|
||||
val z2 = Z(2)
|
||||
val z3 = Z(3)
|
||||
val z4 = Z(4)
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
val outer = ::Outer.call(z1, z2)
|
||||
assertEquals(z1, outer.z1)
|
||||
assertEquals(z2, outer.z2)
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("Z(x=1) Z(x=2) Z(x=3) Z(x=4)", Outer::Inner.call(outer, z3, z4).test)
|
||||
assertEquals("Z(x=1) Z(x=2) Z(x=2) Z(x=4)", outer::Inner.call(z2, z4).test)
|
||||
}
|
||||
}
|
||||
|
||||
val inlineNonNullOuter = InlineNonNullOuter(z1)
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("Z(x=1) Z(x=2) Z(x=3)", InlineNonNullOuter::Inner.call(inlineNonNullOuter, z2, z3).test)
|
||||
assertEquals("Z(x=1) Z(x=2) Z(x=2)", inlineNonNullOuter::Inner.call(z2, z2).test)
|
||||
}
|
||||
|
||||
val inlineNullableOuter = InlineNullableOuter(z1)
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("Z(x=1) Z(x=2) Z(x=3)", InlineNullableOuter::Inner.call(inlineNullableOuter, z2, z3).test)
|
||||
assertEquals("Z(x=1) Z(x=2) Z(x=2)", inlineNullableOuter::Inner.call(z2, z2).test)
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
inline class S(val value: Int) {
|
||||
operator fun plus(other: S): S = S(this.value + other.value)
|
||||
}
|
||||
|
||||
class C {
|
||||
private var nonNullMember: S = S(-1)
|
||||
private var nullableMember: S? = S(-1)
|
||||
|
||||
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(-1)
|
||||
private var nullableTopLevel: S? = S(-1)
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
val zero = S(0)
|
||||
val one = S(1)
|
||||
val two = S(2)
|
||||
|
||||
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())
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(Unit, c.nullableUnboundRef().setter.call(c, zero))
|
||||
assertEquals(zero, c.nullableUnboundRef().call(c))
|
||||
assertEquals(zero, c.nullableUnboundRef().getter.call(c))
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
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 }
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(Unit, nullableTopLevel.setter.call(two))
|
||||
assertEquals(two, nullableTopLevel.call())
|
||||
assertEquals(two, nullableTopLevel.getter.call())
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
inline class S(val value: Int) {
|
||||
operator fun plus(other: S): S = S(this.value + other.value)
|
||||
}
|
||||
|
||||
class C {
|
||||
fun member(x: S, y: Int, z: S?): S = x + S(y) + z!!
|
||||
}
|
||||
|
||||
fun topLevel(x: Int, y: S, z: S?): S = S(x) + 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(): Int = value
|
||||
|
||||
fun S?.extension4(): Int = this!!.value
|
||||
|
||||
fun box(): String {
|
||||
val zero = S(0)
|
||||
val one = S(1)
|
||||
val two = S(2)
|
||||
val four = S(4)
|
||||
val seven = S(7)
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(seven, C::member.call(C(), one, 2, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(seven, ::topLevel.call(1, two, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(seven, S::extension1.call(one, two, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(seven, S::extension2.call(one, two, four))
|
||||
}
|
||||
assertEquals(0, S::extension3.call(zero))
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(0, S?::extension4.call(zero))
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(seven, C()::member.call(one, 2, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(seven, one::extension1.call(two, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(seven, one::extension2.call(two, four))
|
||||
}
|
||||
assertEquals(0, zero::extension3.call())
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(0, zero::extension4.call(zero))
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
inline class Z(val value: Int) {
|
||||
operator fun plus(other: Z): Z = Z(this.value + other.value)
|
||||
}
|
||||
|
||||
object C {
|
||||
@JvmStatic
|
||||
private var p1: Z = Z(-1)
|
||||
|
||||
@JvmStatic
|
||||
private var p2: Z? = Z(-1)
|
||||
|
||||
fun nonNullBoundRef() = this::p1.apply { isAccessible = true }
|
||||
fun nullableBoundRef() = this::p2.apply { isAccessible = true }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val one = Z(1)
|
||||
val two = Z(2)
|
||||
|
||||
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
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
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()
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(Unit, nullableBoundRef.setter.call(two))
|
||||
assertEquals(two, nullableBoundRef.call())
|
||||
assertEquals(two, nullableBoundRef.getter.call())
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KFunction
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
inline class Z(val value: Int) {
|
||||
operator fun plus(other: Z): Z = Z(this.value + other.value)
|
||||
}
|
||||
|
||||
object C {
|
||||
@JvmStatic
|
||||
fun foo(x: Z, y: Int, z: Z?): Z = x + Z(y) + z!!
|
||||
}
|
||||
|
||||
interface I {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun bar(x: Int, y: Z, z: Z?): Z = Z(x) + y + z!!
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val one = Z(1)
|
||||
val two = Z(2)
|
||||
val four = Z(4)
|
||||
val seven = Z(7)
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(seven, C::foo.call(one, 2, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(seven, (I)::bar.call(1, two, four))
|
||||
}
|
||||
|
||||
val unboundFoo = C::class.members.single { it.name == "foo" } as KFunction<*>
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(seven, unboundFoo.call(C, one, 2, four))
|
||||
}
|
||||
|
||||
val unboundBar = I.Companion::class.members.single { it.name == "bar" } as KFunction<*>
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(seven, unboundBar.call(I, 1, two, four))
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
inline class Z(val x: Int) {
|
||||
fun test(a: Int, b: Z, c: Z?) = "$x$a${b.x}${c!!.x}"
|
||||
}
|
||||
|
||||
inline class S(val x: String) {
|
||||
fun test(a: Int, b: Z, c: Z?) = "$x$a${b.x}${c!!.x}"
|
||||
}
|
||||
|
||||
inline class A(val x: Any) {
|
||||
fun test(a: Int, b: Z, c: Z?) = "$x$a${b.x}${c!!.x}"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val two = Z(2)
|
||||
val four = Z(4)
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", Z::test.call(Z(0), 1, two, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", Z(0)::test.call(1, two, four))
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", S::test.call(S("0"), 1, two, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", S("0")::test.call(1, two, four))
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", A::test.call(A(0), 1, two, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", A(0)::test.call(1, two, four))
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
var global = Z(0)
|
||||
|
||||
inline class Z(val x: Int) {
|
||||
var nonNullTest: Z
|
||||
get() = Z(global.x + this.x)
|
||||
set(value) {
|
||||
global = Z(this.x + value.x)
|
||||
}
|
||||
|
||||
var nullableTest: Z?
|
||||
get() = Z(global.x + this.x)
|
||||
set(value) {
|
||||
global = Z(this.x + value!!.x)
|
||||
}
|
||||
}
|
||||
|
||||
inline class S(val x: String) {
|
||||
var nonNullTest: Z
|
||||
get() = Z(global.x + x.toInt())
|
||||
set(value) {
|
||||
global = Z(this.x.toInt() + value.x)
|
||||
}
|
||||
|
||||
var nullableTest: Z?
|
||||
get() = Z(global.x + x.toInt())
|
||||
set(value) {
|
||||
global = Z(this.x.toInt() + value!!.x)
|
||||
}
|
||||
}
|
||||
|
||||
inline class A(val x: Any) {
|
||||
var nonNullTest: Z
|
||||
get() = Z(global.x + this.x as Int)
|
||||
set(value) {
|
||||
global = Z(this.x as Int + value.x)
|
||||
}
|
||||
|
||||
var nullableTest: Z?
|
||||
get() = Z(global.x + this.x as Int)
|
||||
set(value) {
|
||||
global = Z(this.x as Int + value!!.x)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val zZero = Z(0)
|
||||
val zOne = Z(1)
|
||||
val zTwo = Z(2)
|
||||
val zThree = Z(3)
|
||||
val zFour = Z(4)
|
||||
|
||||
val sOne = S("1")
|
||||
|
||||
val aOne = A(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
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, Z::nullableTest.call(zOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, zOne::nullableTest.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, Z::nullableTest.getter.call(zOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, zOne::nullableTest.getter.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
Z::nullableTest.setter.call(zOne, zTwo)
|
||||
assertEquals(zThree, global)
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
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
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, S::nullableTest.call(sOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, sOne::nullableTest.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, S::nullableTest.getter.call(sOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, sOne::nullableTest.getter.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
S::nullableTest.setter.call(sOne, zTwo)
|
||||
assertEquals(zThree, global)
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
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
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, A::nullableTest.call(aOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, aOne::nullableTest.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, A::nullableTest.getter.call(aOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, aOne::nullableTest.getter.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
A::nullableTest.setter.call(aOne, zTwo)
|
||||
assertEquals(zThree, global)
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
aOne::nullableTest.setter.call(zThree)
|
||||
assertEquals(zFour, global)
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
interface ITest {
|
||||
fun test(a: Int, b: Z, c: Z?): String
|
||||
}
|
||||
|
||||
inline class Z(val x: Int) : ITest {
|
||||
override fun test(a: Int, b: Z, c: Z?) = "$x$a${b.x}${c!!.x}"
|
||||
}
|
||||
|
||||
inline class S(val x: String) : ITest {
|
||||
override fun test(a: Int, b: Z, c: Z?) = "$x$a${b.x}${c!!.x}"
|
||||
}
|
||||
|
||||
inline class A(val x: Any) : ITest {
|
||||
override fun test(a: Int, b: Z, c: Z?) = "$x$a${b.x}${c!!.x}"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val two = Z(2)
|
||||
val four = Z(4)
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", Z::test.call(Z(0), 1, two, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", Z(0)::test.call(1, two, four))
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", S::test.call(S("0"), 1, two, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", S("0")::test.call(1, two, four))
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", A::test.call(A(0), 1, two, four))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals("0124", A(0)::test.call(1, two, four))
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+165
@@ -0,0 +1,165 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
var global = Z(0)
|
||||
|
||||
interface ITest {
|
||||
var nonNullTest: Z
|
||||
var nullableTest: Z?
|
||||
}
|
||||
|
||||
inline class Z(val x: Int) : ITest {
|
||||
override var nonNullTest: Z
|
||||
get() = Z(global.x + this.x)
|
||||
set(value) {
|
||||
global = Z(this.x + value.x)
|
||||
}
|
||||
|
||||
override var nullableTest: Z?
|
||||
get() = Z(global.x + this.x)
|
||||
set(value) {
|
||||
global = Z(this.x + value!!.x)
|
||||
}
|
||||
}
|
||||
|
||||
inline class S(val x: String) : ITest {
|
||||
override var nonNullTest: Z
|
||||
get() = Z(global.x + x.toInt())
|
||||
set(value) {
|
||||
global = Z(this.x.toInt() + value.x)
|
||||
}
|
||||
|
||||
override var nullableTest: Z?
|
||||
get() = Z(global.x + x.toInt())
|
||||
set(value) {
|
||||
global = Z(this.x.toInt() + value!!.x)
|
||||
}
|
||||
}
|
||||
|
||||
inline class A(val x: Any) : ITest {
|
||||
override var nonNullTest: Z
|
||||
get() = Z(global.x + this.x as Int)
|
||||
set(value) {
|
||||
global = Z(this.x as Int + value.x)
|
||||
}
|
||||
|
||||
override var nullableTest: Z?
|
||||
get() = Z(global.x + this.x as Int)
|
||||
set(value) {
|
||||
global = Z(this.x as Int + value!!.x)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val zZero = Z(0)
|
||||
val zOne = Z(1)
|
||||
val zTwo = Z(2)
|
||||
val zThree = Z(3)
|
||||
val zFour = Z(4)
|
||||
|
||||
val sOne = S("1")
|
||||
|
||||
val aOne = A(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
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, Z::nullableTest.call(zOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, zOne::nullableTest.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, Z::nullableTest.getter.call(zOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, zOne::nullableTest.getter.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
Z::nullableTest.setter.call(zOne, zTwo)
|
||||
assertEquals(zThree, global)
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
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
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, S::nullableTest.call(sOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, sOne::nullableTest.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, S::nullableTest.getter.call(sOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, sOne::nullableTest.getter.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
S::nullableTest.setter.call(sOne, zTwo)
|
||||
assertEquals(zThree, global)
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
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
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, A::nullableTest.call(aOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, aOne::nullableTest.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, A::nullableTest.getter.call(aOne))
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(zOne, aOne::nullableTest.getter.call())
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
A::nullableTest.setter.call(aOne, zTwo)
|
||||
assertEquals(zThree, global)
|
||||
}
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
aOne::nullableTest.setter.call(zThree)
|
||||
assertEquals(zFour, global)
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KMutableProperty2
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
inline class Z(val value: Int) {
|
||||
operator fun plus(other: Z): Z = Z(this.value + other.value)
|
||||
}
|
||||
|
||||
class C {
|
||||
var nonNullMember: Z = Z(0)
|
||||
var nullableMember: Z? = Z(0)
|
||||
|
||||
private var offset = Z(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(0)
|
||||
var nullableTopLevel: Z? = Z(0)
|
||||
|
||||
private var offset = Z(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(1)
|
||||
val two = Z(2)
|
||||
val three = Z(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())
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(Unit, C::nullableMember.setter.call(c, one))
|
||||
assertEquals(one, C::nullableMember.call(c))
|
||||
assertEquals(one, C::nullableMember.getter.call(c))
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
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(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?>
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(Unit, nonNull_nullableMemExt.setter.call(c, Z(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>
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(Unit, nullable_nonNullMemExt.setter.call(c, Z(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?>
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(Unit, nullable_nullableMemExt.setter.call(c, Z(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())
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(Unit, ::nullableTopLevel.setter.call(one))
|
||||
assertEquals(one, ::nullableTopLevel.call())
|
||||
assertEquals(one, ::nullableTopLevel.getter.call())
|
||||
}
|
||||
|
||||
assertEquals(Unit, Z::nonNull_nonNullExt.setter.call(Z(0), two))
|
||||
assertEquals(three, Z::nonNull_nonNullExt.call(one))
|
||||
assertEquals(three, Z::nonNull_nonNullExt.getter.call(one))
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(Unit, Z::nonNull_nullableExt.setter.call(Z(0), two))
|
||||
assertEquals(three, Z::nonNull_nullableExt.call(one))
|
||||
assertEquals(three, Z::nonNull_nullableExt.getter.call(one))
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(Unit, Z?::nullable_nonNullExt.setter.call(Z(0), two))
|
||||
assertEquals(three, Z?::nullable_nonNullExt.call(one))
|
||||
assertEquals(three, Z?::nullable_nonNullExt.getter.call(one))
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
assertEquals(Unit, Z?::nullable_nullableExt.setter.call(Z(0), two))
|
||||
assertEquals(three, Z?::nullable_nullableExt.call(one))
|
||||
assertEquals(three, Z?::nullable_nullableExt.getter.call(one))
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
// WITH_COROUTINES
|
||||
|
||||
import kotlin.coroutines.startCoroutine
|
||||
import kotlin.reflect.full.callSuspend
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import helpers.*
|
||||
|
||||
inline class Z(val value: Int)
|
||||
|
||||
class C {
|
||||
private var value: Z = Z(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
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
run0 {
|
||||
C::nonNullConsume.callSuspend(c, Z(1))
|
||||
C::nonNullProduce.callSuspend(c).value
|
||||
}.let { assertEquals(1, it) }
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
run0 {
|
||||
C::nullableConsume.callSuspend(c, Z(2))
|
||||
C::nullableProduce.callSuspend(c)!!.value
|
||||
}.let { assertEquals(2, it) }
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
run0 {
|
||||
C::nonNull_nonNullConsumeAndProduce.callSuspend(c, Z(3)).value
|
||||
}.let { assertEquals(3, it) }
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
run0 {
|
||||
C::nonNull_nullableConsumeAndProduce.callSuspend(c, Z(4))!!.value
|
||||
}.let { assertEquals(4, it) }
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
run0 {
|
||||
C::nullable_nonNullConsumeAndProduce.callSuspend(c, Z(5)).value
|
||||
}.let { assertEquals(5, it) }
|
||||
}
|
||||
|
||||
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
|
||||
run0 {
|
||||
C::nullable_nullableConsumeAndProduce.callSuspend(c, Z(6))!!.value
|
||||
}.let { assertEquals(6, it) }
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user