Add tests for KFunction involving value classes

See KT-31141.
This commit is contained in:
wrongwrong
2022-02-18 21:11:56 +09:00
committed by Alexander Udalov
parent c8453ec8b4
commit c4735f9f29
54 changed files with 3535 additions and 888 deletions
@@ -1,29 +0,0 @@
// IGNORE_BACKEND: JS_IR, JS, NATIVE, WASM
// IGNORE_BACKEND: JS_IR_ES6
// WITH_REFLECT
import kotlin.test.assertEquals
inline class Z(val x: Int)
class Outer(val z1: Z) {
inner class Inner(val z2: Z) {
val test = "$z1 $z2"
}
}
inline class InlineOuter(val z1: Z) {
@Suppress("INNER_CLASS_INSIDE_VALUE_CLASS")
inner class Inner(val z2: Z) {
val test = "$z1 $z2"
}
}
fun box(): String {
assertEquals(Z(1), ::Outer.call(Z(1)).z1)
assertEquals("Z(x=1) Z(x=2)", Outer::Inner.call(Outer(Z(1)), Z(2)).test)
assertEquals("Z(x=1) Z(x=3)", Outer(Z(1))::Inner.call(Z(3)).test)
assertEquals("Z(x=1) Z(x=2)", InlineOuter::Inner.call(InlineOuter(Z(1)), Z(2)).test)
assertEquals("Z(x=1) Z(x=3)", InlineOuter(Z(1))::Inner.call(Z(3)).test)
return "OK"
}
@@ -1,37 +0,0 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.reflect.KCallable
import kotlin.reflect.jvm.isAccessible
import kotlin.test.assertEquals
inline class S(val value: String) {
operator fun plus(other: S): S = S(this.value + other.value)
}
class C {
private var member: S = S("")
fun unboundRef() = C::member.apply { isAccessible = true }
fun boundRef() = this::member.apply { isAccessible = true }
}
private var topLevel: S = S("")
fun box(): String {
val c = C()
assertEquals(Unit, c.unboundRef().setter.call(c, S("ab")))
assertEquals(S("ab"), c.unboundRef().call(c))
assertEquals(S("ab"), c.unboundRef().getter.call(c))
assertEquals(Unit, c.boundRef().setter.call(S("cd")))
assertEquals(S("cd"), c.boundRef().call())
assertEquals(S("cd"), c.boundRef().getter.call())
val topLevel = ::topLevel.apply { isAccessible = true }
assertEquals(Unit, topLevel.setter.call(S("ef")))
assertEquals(S("ef"), topLevel.call())
assertEquals(S("ef"), topLevel.getter.call())
return "OK"
}
@@ -1,32 +0,0 @@
// IGNORE_BACKEND: JS_IR, JS, NATIVE, WASM
// IGNORE_BACKEND: JS_IR_ES6
// WITH_REFLECT
import kotlin.test.assertEquals
inline class S(val value: String) {
operator fun plus(other: S): S = S(this.value + other.value)
}
class C {
fun member(x: S, y: String): S = x + S(y)
}
fun topLevel(x: String, y: S): S = S(x) + y
fun S.extension(y: S): S = this + y
fun S.extension2(): String = value
fun box(): String {
assertEquals(S("ab"), C::member.call(C(), S("a"), "b"))
assertEquals(S("cd"), ::topLevel.call("c", S("d")))
assertEquals(S("gh"), S::extension.call(S("g"), S("h")))
assertEquals("_", S::extension2.call(S("_")))
assertEquals(S("ij"), C()::member.call(S("i"), "j"))
assertEquals(S("mn"), S("m")::extension.call(S("n")))
assertEquals("_", S("_")::extension2.call())
return "OK"
}
@@ -4,6 +4,7 @@
import kotlin.reflect.KCallable
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
inline class Z(val x: Int) {
constructor(a: Int, b: Int) : this(a + b)
@@ -13,36 +14,48 @@ inline class L(val x: Long) {
constructor(a: Long, b: Long) : this(a + b)
}
inline class S(val x: String) {
inline class S1(val x: String) {
constructor(a: String, b: String) : this(a + b)
}
inline class S2(val x: String?) {
constructor(a: String?, b: String?) : this(a!! + b!!)
}
inline class A(val x: Any) {
constructor(a: String, b: String) : this(a + b)
}
inline class Z2(val z: Z)
inline class Z3(val z: Z?)
fun box(): String {
val ctorZ1: (Int) -> Z = ::Z
val ctorZ2: (Int, Int) -> Z = ::Z
val ctorZ1_1: (Int) -> Z = ::Z
val ctorZ1_2: (Int, Int) -> Z = ::Z
val ctorL1: (Long) -> L = ::L
val ctorL2: (Long, Long) -> L = ::L
val ctorS1: (String) -> S = ::S
val ctorS2: (String, String) -> S = ::S
val ctorS1_1: (String) -> S1 = ::S1
val ctorS1_2: (String, String) -> S1 = ::S1
val ctorS2_1: (String) -> S2 = ::S2
val ctorS2_2: (String, String) -> S2 = ::S2
val ctorA1: (Any) -> A = ::A
val ctorA2: (String, String) -> A = ::A
assertEquals(Z(42), (ctorZ1 as KCallable<Z>).call(42))
assertEquals(Z(123), (ctorZ2 as KCallable<Z>).call(100, 23))
assertEquals(Z(42), (ctorZ1_1 as KCallable<Z>).call(42))
assertEquals(Z(123), (ctorZ1_2 as KCallable<Z>).call(100, 23))
assertEquals(L(1L), (ctorL1 as KCallable<L>).call(1L))
assertEquals(L(123L), (ctorL2 as KCallable<L>).call(100L, 23L))
assertEquals(S("abc"), (ctorS1 as KCallable<S>).call("abc"))
assertEquals(S("abc"), (ctorS2 as KCallable<S>).call("ab", "c"))
assertEquals(S1("abc"), (ctorS1_1 as KCallable<S1>).call("abc"))
assertEquals(S1("abc"), (ctorS1_2 as KCallable<S1>).call("ab", "c"))
assertEquals(S2("abc"), (ctorS2_1 as KCallable<S2>).call("abc"))
assertEquals(S2("abc"), (ctorS2_2 as KCallable<S2>).call("ab", "c"))
assertEquals(A("abc"), (ctorA1 as KCallable<A>).call("abc"))
assertEquals(A("abc"), (ctorA2 as KCallable<A>).call("a", "bc"))
assertEquals(Z2(Z(42)), ::Z2.call(Z(42)))
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(Z3(Z(42)), ::Z3.call(Z(42)))
}
return "OK"
}
@@ -10,8 +10,10 @@ inline class Z2(internal val x: Z)
inline class L(internal val x: Long)
inline class L2(internal val x: L)
inline class A(internal val x: Any?)
inline class A2(internal val x: A)
inline class A1(internal val x: Any?)
inline class A1_2(internal val x: A1)
inline class A2(internal val x: Any)
inline class A2_2(internal val x: A2)
fun box(): String {
assertEquals(42, Z::x.call(Z(42)))
@@ -20,10 +22,12 @@ fun box(): String {
assertEquals(1234L, L::x.call(L(1234L)))
assertEquals(1234L, L(1234L)::x.call())
assertEquals("abc", A::x.call(A("abc")))
assertEquals("abc", A("abc")::x.call())
assertEquals(null, A::x.call(A(null)))
assertEquals(null, A(null)::x.call())
assertEquals("abc", A1::x.call(A1("abc")))
assertEquals("abc", A1("abc")::x.call())
assertEquals(null, A1::x.call(A1(null)))
assertEquals(null, A1(null)::x.call())
assertEquals("abc", A2::x.call(A2("abc")))
assertEquals("abc", A2("abc")::x.call())
assertEquals(Z(42), Z2::x.call(Z2(Z(42))))
assertEquals(Z(42), Z2(Z(42))::x.call())
@@ -31,10 +35,12 @@ fun box(): String {
assertEquals(L(1234L), L2::x.call(L2(L(1234L))))
assertEquals(L(1234L), L2(L(1234L))::x.call())
assertEquals(A("abc"), A2::x.call(A2(A("abc"))))
assertEquals(A("abc"), A2(A("abc"))::x.call())
assertEquals(A(null), A2::x.call(A2(A(null))))
assertEquals(A(null), A2(A(null))::x.call())
assertEquals(A1("abc"), A1_2::x.call(A1_2(A1("abc"))))
assertEquals(A1("abc"), A1_2(A1("abc"))::x.call())
assertEquals(A1(null), A1_2::x.call(A1_2(A1(null))))
assertEquals(A1(null), A1_2(A1(null))::x.call())
assertEquals(A2("abc"), A2_2::x.call(A2_2(A2("abc"))))
assertEquals(A2("abc"), A2_2(A2("abc"))::x.call())
return "OK"
}
}
@@ -1,33 +0,0 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_REFLECT
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.jvm.isAccessible
import kotlin.test.assertEquals
inline class S(val value: String) {
operator fun plus(other: S): S = S(this.value + other.value)
}
object C {
@JvmStatic
private var p: S = S("")
fun boundRef() = this::p.apply { isAccessible = true }
}
fun box(): String {
val unboundRef = C::class.members.single { it.name == "p" } as KMutableProperty1<C, S>
unboundRef.isAccessible = true
assertEquals(Unit, unboundRef.setter.call(C, S("ab")))
assertEquals(S("ab"), unboundRef.call(C))
assertEquals(S("ab"), unboundRef.getter.call(C))
val boundRef = C.boundRef()
assertEquals(Unit, boundRef.setter.call(S("cd")))
assertEquals(S("cd"), boundRef.call())
assertEquals(S("cd"), boundRef.getter.call())
return "OK"
}
@@ -0,0 +1,50 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
inline class S(val x: String)
class Outer(val z1: S, val z2: S?) {
inner class Inner(val z3: S, val z4: S?) {
val test = "$z1 $z2 $z3 $z4"
}
}
inline class InlineNonNullOuter(val z1: S) {
@Suppress("INNER_CLASS_INSIDE_VALUE_CLASS")
inner class Inner(val z2: S, val z3: S?) {
val test = "$z1 $z2 $z3"
}
}
inline class InlineNullableOuter(val z1: S?) {
@Suppress("INNER_CLASS_INSIDE_VALUE_CLASS")
inner class Inner(val z2: S, val z3: S?) {
val test = "$z1 $z2 $z3"
}
}
fun box(): String {
val z1 = S("1")
val z2 = S("2")
val z3 = S("3")
val z4 = S("4")
val outer = ::Outer.call(z1, z2)
assertEquals(z1, outer.z1)
assertEquals(z2, outer.z2)
assertEquals("S(x=1) S(x=2) S(x=3) S(x=4)", Outer::Inner.call(outer, z3, z4).test)
assertEquals("S(x=1) S(x=2) S(x=2) S(x=4)", outer::Inner.call(z2, z4).test)
val inlineNonNullOuter = InlineNonNullOuter(z1)
assertEquals("S(x=1) S(x=2) S(x=3)", InlineNonNullOuter::Inner.call(inlineNonNullOuter, z2, z3).test)
assertEquals("S(x=1) S(x=2) S(x=2)", inlineNonNullOuter::Inner.call(z2, z2).test)
val inlineNullableOuter = InlineNullableOuter(z1)
assertEquals("S(x=1) S(x=2) S(x=3)", InlineNullableOuter::Inner.call(inlineNullableOuter, z2, z3).test)
assertEquals("S(x=1) S(x=2) S(x=2)", inlineNullableOuter::Inner.call(z2, z2).test)
return "OK"
}
@@ -0,0 +1,53 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.reflect.jvm.isAccessible
import kotlin.test.assertEquals
inline class S(val value: String) {
operator fun plus(other: S): S = S(this.value + other.value)
}
class C {
private var nonNullMember: S = S("")
private var nullableMember: S? = S("")
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("")
private var nullableTopLevel: S? = S("")
fun box(): String {
val c = C()
assertEquals(Unit, c.nonNullUnboundRef().setter.call(c, S("ab")))
assertEquals(S("ab"), c.nonNullUnboundRef().call(c))
assertEquals(S("ab"), c.nonNullUnboundRef().getter.call(c))
assertEquals(Unit, c.nonNullBoundRef().setter.call(S("cd")))
assertEquals(S("cd"), c.nonNullBoundRef().call())
assertEquals(S("cd"), c.nonNullBoundRef().getter.call())
assertEquals(Unit, c.nullableUnboundRef().setter.call(c, S("ab")))
assertEquals(S("ab"), c.nullableUnboundRef().call(c))
assertEquals(S("ab"), c.nullableUnboundRef().getter.call(c))
assertEquals(Unit, c.nullableBoundRef().setter.call(S("cd")))
assertEquals(S("cd"), c.nullableBoundRef().call())
assertEquals(S("cd"), c.nullableBoundRef().getter.call())
val nonNullTopLevel = ::nonNullTopLevel.apply { isAccessible = true }
assertEquals(Unit, nonNullTopLevel.setter.call(S("ef")))
assertEquals(S("ef"), nonNullTopLevel.call())
assertEquals(S("ef"), nonNullTopLevel.getter.call())
val nullableTopLevel = ::nullableTopLevel.apply { isAccessible = true }
assertEquals(Unit, nullableTopLevel.setter.call(S("ef")))
assertEquals(S("ef"), nullableTopLevel.call())
assertEquals(S("ef"), nullableTopLevel.getter.call())
return "OK"
}
@@ -0,0 +1,46 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
inline class S(val value: String) {
operator fun plus(other: S): S = S(this.value + other.value)
}
class C {
fun member(x: S, y: String, z: S?): S = x + S(y) + z!!
}
fun topLevel(x: String, 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(): String = value
fun S?.extension4(): String = this!!.value
fun box(): String {
assertEquals(S("abc"), C::member.call(C(), S("a"), "b", S("c")))
assertEquals(S("def"), ::topLevel.call("d", S("e"), S("f")))
assertEquals(S("ghi"), S::extension1.call(S("g"), S("h"), S("i")))
assertEquals(S("jkl"), S::extension2.call(S("j"), S("k"), S("l")))
assertEquals("_", S::extension3.call(S("_")))
assertEquals("_", S?::extension4.call(S("_")))
assertEquals(S("mno"), C()::member.call(S("m"), "n", S("o")))
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("pqr"), S("p")::extension1.call(S("q"), "r"))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("stu"), S("s")::extension2.call(S("t"), "u"))
}
assertEquals("_", S("_")::extension3.call())
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("_", S("_")::extension4.call(S("_")))
}
return "OK"
}
@@ -0,0 +1,48 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_REFLECT
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.jvm.isAccessible
import kotlin.test.assertEquals
inline class S(val value: String) {
operator fun plus(other: S): S = S(this.value + other.value)
}
object C {
@JvmStatic
private var p1: S = S("")
@JvmStatic
private var p2: S? = S("")
fun nonNullBoundRef() = this::p1.apply { isAccessible = true }
fun nullableBoundRef() = this::p2.apply { isAccessible = true }
}
fun box(): String {
val nonNullUnboundRef = C::class.members.single { it.name == "p1" } as KMutableProperty1<C, S>
nonNullUnboundRef.isAccessible = true
assertEquals(Unit, nonNullUnboundRef.setter.call(C, S("ab")))
assertEquals(S("ab"), nonNullUnboundRef.call(C))
assertEquals(S("ab"), nonNullUnboundRef.getter.call(C))
val nullableUnboundRef = C::class.members.single { it.name == "p2" } as KMutableProperty1<C, S?>
nullableUnboundRef.isAccessible = true
assertEquals(Unit, nullableUnboundRef.setter.call(C, S("ab")))
assertEquals(S("ab"), nullableUnboundRef.call(C))
assertEquals(S("ab"), nullableUnboundRef.getter.call(C))
val nonNullBoundRef = C.nonNullBoundRef()
assertEquals(Unit, nonNullBoundRef.setter.call(S("cd")))
assertEquals(S("cd"), nonNullBoundRef.call())
assertEquals(S("cd"), nonNullBoundRef.getter.call())
val nullableBoundRef = C.nullableBoundRef()
assertEquals(Unit, nullableBoundRef.setter.call(S("cd")))
assertEquals(S("cd"), nullableBoundRef.call())
assertEquals(S("cd"), nullableBoundRef.getter.call())
return "OK"
}
@@ -11,25 +11,25 @@ inline class S(val value: String) {
object C {
@JvmStatic
fun foo(x: S, y: String): S = x + S(y)
fun foo(x: S, y: String, z: S?): S = x + S(y) + z!!
}
interface I {
companion object {
@JvmStatic
fun bar(x: String, y: S): S = S(x) + y
fun bar(x: String, y: S, z: S?): S = S(x) + y + z!!
}
}
fun box(): String {
assertEquals(S("ab"), C::foo.call(S("a"), "b"))
assertEquals(S("cd"), (I)::bar.call("c", S("d")))
assertEquals(S("abc"), C::foo.call(S("a"), "b", S("c")))
assertEquals(S("def"), (I)::bar.call("d", S("e"), S("f")))
val unboundFoo = C::class.members.single { it.name == "foo" } as KFunction<*>
assertEquals(S("ef"), unboundFoo.call(C, S("e"), "f"))
assertEquals(S("ghi"), unboundFoo.call(C, S("g"), "h", S("i")))
val unboundBar = I.Companion::class.members.single { it.name == "bar" } as KFunction<*>
assertEquals(S("gh"), unboundBar.call(I, "g", S("h")))
assertEquals(S("jkl"), unboundBar.call(I, "j", S("k"), S("l")))
return "OK"
}
@@ -0,0 +1,32 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
inline class S(val x: String) {
fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
inline class Z(val x: Int) {
fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
inline class A(val x: Any) {
fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
fun box(): String {
val plus = S("+")
val aster = S("*")
assertEquals("42-+*", S::test.call(S("42"), "-", plus, aster))
assertEquals("42-+*", S("42")::test.call("-", plus, aster))
assertEquals("42-+*", Z::test.call(Z(42), "-", plus, aster))
assertEquals("42-+*", Z(42)::test.call("-", plus, aster))
assertEquals("42-+*", A::test.call(A("42"), "-", plus, aster))
assertEquals("42-+*", A("42")::test.call("-", plus, aster))
return "OK"
}
@@ -0,0 +1,112 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
var global = S("")
inline class S(val x: String) {
var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
inline class Z(val x: Int) {
var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
inline class A(val x: Any) {
var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
fun box(): String {
global = S("")
assertEquals(S("42"), S::nonNullTest.call(S("42")))
assertEquals(S("42"), S("42")::nonNullTest.call())
assertEquals(S("42"), S::nonNullTest.getter.call(S("42")))
assertEquals(S("42"), S("42")::nonNullTest.getter.call())
S::nonNullTest.setter.call(S("42"), S("S-"))
assertEquals(S("S-42"), global)
S("42")::nonNullTest.setter.call(S("S+"))
assertEquals(S("S+42"), global)
global = S("")
assertEquals(S("42"), S::nullableTest.call(S("42")))
assertEquals(S("42"), S("42")::nullableTest.call())
assertEquals(S("42"), S::nullableTest.getter.call(S("42")))
assertEquals(S("42"), S("42")::nullableTest.getter.call())
S::nullableTest.setter.call(S("42"), S("S-"))
assertEquals(S("S-42"), global)
S("42")::nullableTest.setter.call(S("S+"))
assertEquals(S("S+42"), global)
global = S("")
assertEquals(S("42"), Z::nonNullTest.call(Z(42)))
assertEquals(S("42"), Z(42)::nonNullTest.call())
assertEquals(S("42"), Z::nonNullTest.getter.call(Z(42)))
assertEquals(S("42"), Z(42)::nonNullTest.getter.call())
Z::nonNullTest.setter.call(Z(42), S("Z-"))
assertEquals(S("Z-42"), global)
Z(42)::nonNullTest.setter.call(S("Z+"))
assertEquals(S("Z+42"), global)
global = S("")
assertEquals(S("42"), Z::nullableTest.call(Z(42)))
assertEquals(S("42"), Z(42)::nullableTest.call())
assertEquals(S("42"), Z::nullableTest.getter.call(Z(42)))
assertEquals(S("42"), Z(42)::nullableTest.getter.call())
Z::nullableTest.setter.call(Z(42), S("Z-"))
assertEquals(S("Z-42"), global)
Z(42)::nullableTest.setter.call(S("Z+"))
assertEquals(S("Z+42"), global)
global = S("")
assertEquals(S("42"), A::nonNullTest.call(A(42)))
assertEquals(S("42"), A(42)::nonNullTest.call())
assertEquals(S("42"), A::nonNullTest.getter.call(A(42)))
assertEquals(S("42"), A(42)::nonNullTest.getter.call())
A::nonNullTest.setter.call(A(42), S("A-"))
assertEquals(S("A-42"), global)
A(42)::nonNullTest.setter.call(S("A+"))
assertEquals(S("A+42"), global)
global = S("")
assertEquals(S("42"), A::nullableTest.call(A(42)))
assertEquals(S("42"), A(42)::nullableTest.call())
assertEquals(S("42"), A::nullableTest.getter.call(A(42)))
assertEquals(S("42"), A(42)::nullableTest.getter.call())
A::nullableTest.setter.call(A(42), S("A-"))
assertEquals(S("A-42"), global)
A(42)::nullableTest.setter.call(S("A+"))
assertEquals(S("A+42"), global)
return "OK"
}
@@ -0,0 +1,36 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
interface ITest {
fun test(a: String, b: S, c: S?): String
}
inline class S(val x: String) : ITest {
override fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
inline class Z(val x: Int) : ITest {
override fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
inline class A(val x: Any) : ITest {
override fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
fun box(): String {
val plus = S("+")
val aster = S("*")
assertEquals("42-+*", S::test.call(S("42"), "-", plus, aster))
assertEquals("42-+*", S("42")::test.call("-", plus, aster))
assertEquals("42-+*", Z::test.call(Z(42), "-", plus, aster))
assertEquals("42-+*", Z(42)::test.call("-", plus, aster))
assertEquals("42-+*", A::test.call(A("42"), "-", plus, aster))
assertEquals("42-+*", A("42")::test.call("-", plus, aster))
return "OK"
}
@@ -0,0 +1,117 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
var global = S("")
interface ITest {
var nonNullTest: S
var nullableTest: S?
}
inline class S(val x: String) : ITest {
override var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
override var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
inline class Z(val x: Int) : ITest {
override var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
override var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
inline class A(val x: Any) : ITest {
override var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
override var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
fun box(): String {
global = S("")
assertEquals(S("42"), S::nonNullTest.call(S("42")))
assertEquals(S("42"), S("42")::nonNullTest.call())
assertEquals(S("42"), S::nonNullTest.getter.call(S("42")))
assertEquals(S("42"), S("42")::nonNullTest.getter.call())
S::nonNullTest.setter.call(S("42"), S("S-"))
assertEquals(S("S-42"), global)
S("42")::nonNullTest.setter.call(S("S+"))
assertEquals(S("S+42"), global)
global = S("")
assertEquals(S("42"), S::nullableTest.call(S("42")))
assertEquals(S("42"), S("42")::nullableTest.call())
assertEquals(S("42"), S::nullableTest.getter.call(S("42")))
assertEquals(S("42"), S("42")::nullableTest.getter.call())
S::nullableTest.setter.call(S("42"), S("S-"))
assertEquals(S("S-42"), global)
S("42")::nullableTest.setter.call(S("S+"))
assertEquals(S("S+42"), global)
global = S("")
assertEquals(S("42"), Z::nonNullTest.call(Z(42)))
assertEquals(S("42"), Z(42)::nonNullTest.call())
assertEquals(S("42"), Z::nonNullTest.getter.call(Z(42)))
assertEquals(S("42"), Z(42)::nonNullTest.getter.call())
Z::nonNullTest.setter.call(Z(42), S("Z-"))
assertEquals(S("Z-42"), global)
Z(42)::nonNullTest.setter.call(S("Z+"))
assertEquals(S("Z+42"), global)
global = S("")
assertEquals(S("42"), Z::nullableTest.call(Z(42)))
assertEquals(S("42"), Z(42)::nullableTest.call())
assertEquals(S("42"), Z::nullableTest.getter.call(Z(42)))
assertEquals(S("42"), Z(42)::nullableTest.getter.call())
Z::nullableTest.setter.call(Z(42), S("Z-"))
assertEquals(S("Z-42"), global)
Z(42)::nullableTest.setter.call(S("Z+"))
assertEquals(S("Z+42"), global)
global = S("")
assertEquals(S("42"), A::nonNullTest.call(A(42)))
assertEquals(S("42"), A(42)::nonNullTest.call())
assertEquals(S("42"), A::nonNullTest.getter.call(A(42)))
assertEquals(S("42"), A(42)::nonNullTest.getter.call())
A::nonNullTest.setter.call(A(42), S("A-"))
assertEquals(S("A-42"), global)
A(42)::nonNullTest.setter.call(S("A+"))
assertEquals(S("A+42"), global)
global = S("")
assertEquals(S("42"), A::nullableTest.call(A(42)))
assertEquals(S("42"), A(42)::nullableTest.call())
assertEquals(S("42"), A::nullableTest.getter.call(A(42)))
assertEquals(S("42"), A(42)::nullableTest.getter.call())
A::nullableTest.setter.call(A(42), S("A-"))
assertEquals(S("A-42"), global)
A(42)::nullableTest.setter.call(S("A+"))
assertEquals(S("A+42"), global)
return "OK"
}
@@ -0,0 +1,116 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.reflect.KMutableProperty2
import kotlin.test.assertEquals
inline class S(val value: String) {
operator fun plus(other: S): S = S(this.value + other.value)
}
class C {
var nonNullMember: S = S("")
var nullableMember: S? = S("")
private var suffix = S("")
var S.nonNull_nonNullMemExt: S
get() = this + suffix
set(value) { suffix = this + value }
var S.nonNull_nullableMemExt: S?
get() = this + suffix
set(value) { suffix = this + value!! }
var S?.nullable_nonNullMemExt: S
get() = this!! + suffix
set(value) { suffix = this!! + value }
var S?.nullable_nullableMemExt: S?
get() = this!! + suffix
set(value) { suffix = this!! + value!! }
}
var nonNullTopLevel: S = S("")
var nullableTopLevel: S? = S("")
private var suffix = S("")
var S.nonNull_nonNullExt: S
get() = this + suffix
set(value) { suffix = this + value }
var S.nonNull_nullableExt: S?
get() = this + suffix
set(value) { suffix = this + value!! }
var S?.nullable_nonNullExt: S
get() = this!! + suffix
set(value) { suffix = this!! + value }
var S?.nullable_nullableExt: S?
get() = this!! + suffix
set(value) { suffix = this!! + value!! }
fun box(): String {
val c = C()
assertEquals(Unit, C::nonNullMember.setter.call(c, S("ab")))
assertEquals(S("ab"), C::nonNullMember.call(c))
assertEquals(S("ab"), C::nonNullMember.getter.call(c))
assertEquals(Unit, c::nonNullMember.setter.call(S("cd")))
assertEquals(S("cd"), c::nonNullMember.call())
assertEquals(S("cd"), c::nonNullMember.getter.call())
assertEquals(Unit, C::nullableMember.setter.call(c, S("ab")))
assertEquals(S("ab"), C::nullableMember.call(c))
assertEquals(S("ab"), C::nullableMember.getter.call(c))
assertEquals(Unit, c::nullableMember.setter.call(S("cd")))
assertEquals(S("cd"), c::nullableMember.call())
assertEquals(S("cd"), c::nullableMember.getter.call())
val nonNull_nonNullMemExt = C::class.members.single { it.name == "nonNull_nonNullMemExt" } as KMutableProperty2<C, S, S>
assertEquals(Unit, nonNull_nonNullMemExt.setter.call(c, S(""), S("f")))
assertEquals(S("ef"), nonNull_nonNullMemExt.call(c, S("e")))
assertEquals(S("ef"), nonNull_nonNullMemExt.getter.call(c, S("e")))
val nonNull_nullableMemExt = C::class.members.single { it.name == "nonNull_nullableMemExt" } as KMutableProperty2<C, S, S?>
assertEquals(Unit, nonNull_nullableMemExt.setter.call(c, S(""), S("f")))
assertEquals(S("ef"), nonNull_nullableMemExt.call(c, S("e")))
assertEquals(S("ef"), nonNull_nullableMemExt.getter.call(c, S("e")))
val nullable_nonNullMemExt = C::class.members.single { it.name == "nullable_nonNullMemExt" } as KMutableProperty2<C, S?, S>
assertEquals(Unit, nullable_nonNullMemExt.setter.call(c, S(""), S("f")))
assertEquals(S("ef"), nullable_nonNullMemExt.call(c, S("e")))
assertEquals(S("ef"), nullable_nonNullMemExt.getter.call(c, S("e")))
val nullable_nullableMemExt = C::class.members.single { it.name == "nullable_nullableMemExt" } as KMutableProperty2<C, S?, S?>
assertEquals(Unit, nullable_nullableMemExt.setter.call(c, S(""), S("f")))
assertEquals(S("ef"), nullable_nullableMemExt.call(c, S("e")))
assertEquals(S("ef"), nullable_nullableMemExt.getter.call(c, S("e")))
assertEquals(Unit, ::nonNullTopLevel.setter.call(S("gh")))
assertEquals(S("gh"), ::nonNullTopLevel.call())
assertEquals(S("gh"), ::nonNullTopLevel.getter.call())
assertEquals(Unit, ::nullableTopLevel.setter.call(S("gh")))
assertEquals(S("gh"), ::nullableTopLevel.call())
assertEquals(S("gh"), ::nullableTopLevel.getter.call())
assertEquals(Unit, S::nonNull_nonNullExt.setter.call(S(""), S("j")))
assertEquals(S("ij"), S::nonNull_nonNullExt.call(S("i")))
assertEquals(S("ij"), S::nonNull_nonNullExt.getter.call(S("i")))
assertEquals(Unit, S::nonNull_nullableExt.setter.call(S(""), S("j")))
assertEquals(S("ij"), S::nonNull_nullableExt.call(S("i")))
assertEquals(S("ij"), S::nonNull_nullableExt.getter.call(S("i")))
assertEquals(Unit, S?::nullable_nonNullExt.setter.call(S(""), S("j")))
assertEquals(S("ij"), S?::nullable_nonNullExt.call(S("i")))
assertEquals(S("ij"), S?::nullable_nonNullExt.getter.call(S("i")))
assertEquals(Unit, S?::nullable_nullableExt.setter.call(S(""), S("j")))
assertEquals(S("ij"), S?::nullable_nullableExt.call(S("i")))
assertEquals(S("ij"), S?::nullable_nullableExt.getter.call(S("i")))
return "OK"
}
@@ -0,0 +1,61 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
// WITH_COROUTINES
import kotlin.coroutines.startCoroutine
import kotlin.reflect.full.callSuspend
import kotlin.test.assertEquals
import helpers.*
inline class S(val value: String)
class C {
private var value: S = S("")
suspend fun nonNullConsume(z: S) { value = z }
suspend fun nonNullProduce(): S = value
suspend fun nullableConsume(z: S?) { value = z!! }
suspend fun nullableProduce(): S? = value
suspend fun nonNull_nonNullConsumeAndProduce(z: S): S = z
suspend fun nonNull_nullableConsumeAndProduce(z: S): S? = z
suspend fun nullable_nonNullConsumeAndProduce(z: S?): S = z!!
suspend fun nullable_nullableConsumeAndProduce(z: S?): S? = z
}
private fun run0(f: suspend () -> String): String {
var result = ""
f.startCoroutine(handleResultContinuation { result = it })
return result
}
fun box(): String {
val c = C()
run0 {
C::nonNullConsume.callSuspend(c, S("nonNull"))
C::nonNullProduce.callSuspend(c).value
}.let { assertEquals("nonNull", it) }
run0 {
C::nullableConsume.callSuspend(c, S("nullable"))
C::nullableProduce.callSuspend(c)!!.value
}.let { assertEquals("nullable", it) }
run0 {
C::nonNull_nonNullConsumeAndProduce.callSuspend(c, S("nonNull_nonNull")).value
}.let { assertEquals("nonNull_nonNull", it) }
run0 {
C::nonNull_nullableConsumeAndProduce.callSuspend(c, S("nonNull_nullable"))!!.value
}.let { assertEquals("nonNull_nullable", it) }
run0 {
C::nullable_nonNullConsumeAndProduce.callSuspend(c, S("nullable_nonNull")).value
}.let { assertEquals("nullable_nonNull", it) }
run0 {
C::nullable_nullableConsumeAndProduce.callSuspend(c, S("nullable_nullable"))!!.value
}.let { assertEquals("nullable_nullable", it) }
return "OK"
}
@@ -1,36 +0,0 @@
// IGNORE_BACKEND: JS_IR, JS, NATIVE, WASM
// IGNORE_BACKEND: JS_IR_ES6
// WITH_REFLECT
import kotlin.test.assertEquals
inline class Z(val x: Int) {
fun test(a: String, b: S) = "$x$a${b.x}"
}
inline class L(val x: Long) {
fun test(a: String, b: S) = "$x$a${b.x}"
}
inline class S(val x: String) {
fun test(a: String, b: S) = "$x$a${b.x}"
}
inline class A(val x: Any) {
fun test(a: String, b: S) = "$x$a${b.x}"
}
fun box(): String {
assertEquals("42-+", Z::test.call(Z(42), "-", S("+")))
assertEquals("42-+", Z(42)::test.call("-", S("+")))
assertEquals("42-+", L::test.call(L(42L), "-", S("+")))
assertEquals("42-+", L(42L)::test.call("-", S("+")))
assertEquals("42-+", S::test.call(S("42"), "-", S("+")))
assertEquals("42-+", S("42")::test.call("-", S("+")))
assertEquals("42-+", A::test.call(A("42"), "-", S("+")))
assertEquals("42-+", A("42")::test.call("-", S("+")))
return "OK"
}
@@ -1,82 +0,0 @@
// IGNORE_BACKEND: JS_IR, JS, NATIVE, WASM
// IGNORE_BACKEND: JS_IR_ES6
// WITH_REFLECT
import kotlin.test.assertEquals
var global = S("")
inline class Z(val x: Int) {
var test: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
}
inline class L(val x: Long) {
var test: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
}
inline class S(val x: String) {
var test: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
}
inline class A(val x: Any) {
var test: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
}
fun box(): String {
global = S("")
assertEquals(S("42"), Z::test.call(Z(42)))
assertEquals(S("42"), Z(42)::test.call())
assertEquals(S("42"), Z::test.getter.call(Z(42)))
assertEquals(S("42"), Z(42)::test.getter.call())
Z::test.setter.call(Z(42), S("Z-"))
assertEquals(S("Z-42"), global)
Z(42)::test.setter.call(S("Z+"))
assertEquals(S("Z+42"), global)
global = S("")
assertEquals(S("42"), L::test.call(L(42L)))
assertEquals(S("42"), L(42L)::test.call())
assertEquals(S("42"), L::test.getter.call(L(42L)))
assertEquals(S("42"), L(42L)::test.getter.call())
L::test.setter.call(L(42L), S("L-"))
assertEquals(S("L-42"), global)
L(42L)::test.setter.call(S("L+"))
assertEquals(S("L+42"), global)
global = S("")
assertEquals(S("42"), S::test.call(S("42")))
assertEquals(S("42"), S("42")::test.call())
assertEquals(S("42"), S::test.getter.call(S("42")))
assertEquals(S("42"), S("42")::test.getter.call())
S::test.setter.call(S("42"), S("S-"))
assertEquals(S("S-42"), global)
S("42")::test.setter.call(S("S+"))
assertEquals(S("S+42"), global)
global = S("")
assertEquals(S("42"), A::test.call(A(42)))
assertEquals(S("42"), A(42)::test.call())
assertEquals(S("42"), A::test.getter.call(A(42)))
assertEquals(S("42"), A(42)::test.getter.call())
A::test.setter.call(A(42), S("A-"))
assertEquals(S("A-42"), global)
A(42)::test.setter.call(S("A+"))
assertEquals(S("A+42"), global)
return "OK"
}
@@ -0,0 +1,63 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
inline class S(val x: String?)
class Outer(val z1: S, val z2: S?) {
inner class Inner(val z3: S, val z4: S?) {
val test = "$z1 $z2 $z3 $z4"
}
}
inline class InlineNonNullOuter(val z1: S) {
@Suppress("INNER_CLASS_INSIDE_VALUE_CLASS")
inner class Inner(val z2: S, val z3: S?) {
val test = "$z1 $z2 $z3"
}
}
inline class InlineNullableOuter(val z1: S?) {
@Suppress("INNER_CLASS_INSIDE_VALUE_CLASS")
inner class Inner(val z2: S, val z3: S?) {
val test = "$z1 $z2 $z3"
}
}
fun box(): String {
val z1 = S("1")
val z2 = S("2")
val z3 = S("3")
val z4 = S("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("S(x=1) S(x=2) S(x=3) S(x=4)", Outer::Inner.call(outer, z3, z4).test)
assertEquals("S(x=1) S(x=2) S(x=2) S(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("S(x=1) S(x=2) S(x=3)", InlineNonNullOuter::Inner.call(inlineNonNullOuter, z2, z3).test)
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("S(x=1) S(x=2) S(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("S(x=1) S(x=2) S(x=3)", InlineNullableOuter::Inner.call(inlineNullableOuter, z2, z3).test)
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("S(x=1) S(x=2) S(x=2)", inlineNullableOuter::Inner.call(z2, z2).test)
}
return "OK"
}
@@ -0,0 +1,60 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.reflect.jvm.isAccessible
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
inline class S(val value: String?) {
operator fun plus(other: S): S = S(this.value!! + other.value!!)
}
class C {
private var nonNullMember: S = S("")
private var nullableMember: S? = S("")
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("")
private var nullableTopLevel: S? = S("")
fun box(): String {
val c = C()
assertEquals(Unit, c.nonNullUnboundRef().setter.call(c, S("ab")))
assertEquals(S("ab"), c.nonNullUnboundRef().call(c))
assertEquals(S("ab"), c.nonNullUnboundRef().getter.call(c))
assertEquals(Unit, c.nonNullBoundRef().setter.call(S("cd")))
assertEquals(S("cd"), c.nonNullBoundRef().call())
assertEquals(S("cd"), 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, S("ab")))
assertEquals(S("ab"), c.nullableUnboundRef().call(c))
assertEquals(S("ab"), 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(S("cd")))
assertEquals(S("cd"), c.nullableBoundRef().call())
assertEquals(S("cd"), c.nullableBoundRef().getter.call())
}
val nonNullTopLevel = ::nonNullTopLevel.apply { isAccessible = true }
assertEquals(Unit, nonNullTopLevel.setter.call(S("ef")))
assertEquals(S("ef"), nonNullTopLevel.call())
assertEquals(S("ef"), 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(S("ef")))
assertEquals(S("ef"), nullableTopLevel.call())
assertEquals(S("ef"), nullableTopLevel.getter.call())
}
return "OK"
}
@@ -0,0 +1,58 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
inline class S(val value: String?) {
operator fun plus(other: S): S = S(this.value + other.value)
}
class C {
fun member(x: S, y: String, z: S?): S = x + S(y) + z!!
}
fun topLevel(x: String, 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(): String = value!!
fun S?.extension4(): String = this!!.value!!
fun box(): String {
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("abc"), C::member.call(C(), S("a"), "b", S("c")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("def"), ::topLevel.call("d", S("e"), S("f")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("ghi"), S::extension1.call(S("g"), S("h"), S("i")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("jkl"), S::extension2.call(S("j"), S("k"), S("l")))
}
assertEquals("_", S::extension3.call(S("_")))
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("_", S?::extension4.call(S("_")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("mno"), C()::member.call(S("m"), "n", S("o")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("pqr"), S("p")::extension1.call(S("q"), "r"))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("stu"), S("s")::extension2.call(S("t"), "u"))
}
assertEquals("_", S("_")::extension3.call())
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("_", S("_")::extension4.call(S("_")))
}
return "OK"
}
@@ -0,0 +1,53 @@
// 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 S(val value: String?) {
operator fun plus(other: S): S = S(this.value!! + other.value!!)
}
object C {
@JvmStatic
private var p1: S = S("")
@JvmStatic
private var p2: S? = S("")
fun nonNullBoundRef() = this::p1.apply { isAccessible = true }
fun nullableBoundRef() = this::p2.apply { isAccessible = true }
}
fun box(): String {
val nonNullUnboundRef = C::class.members.single { it.name == "p1" } as KMutableProperty1<C, S>
nonNullUnboundRef.isAccessible = true
assertEquals(Unit, nonNullUnboundRef.setter.call(C, S("ab")))
assertEquals(S("ab"), nonNullUnboundRef.call(C))
assertEquals(S("ab"), nonNullUnboundRef.getter.call(C))
val nullableUnboundRef = C::class.members.single { it.name == "p2" } as KMutableProperty1<C, S?>
nullableUnboundRef.isAccessible = true
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(Unit, nullableUnboundRef.setter.call(C, S("ab")))
assertEquals(S("ab"), nullableUnboundRef.call(C))
assertEquals(S("ab"), nullableUnboundRef.getter.call(C))
}
val nonNullBoundRef = C.nonNullBoundRef()
assertEquals(Unit, nonNullBoundRef.setter.call(S("cd")))
assertEquals(S("cd"), nonNullBoundRef.call())
assertEquals(S("cd"), 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(S("cd")))
assertEquals(S("cd"), nullableBoundRef.call())
assertEquals(S("cd"), nullableBoundRef.getter.call())
}
return "OK"
}
@@ -0,0 +1,44 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// WITH_REFLECT
import kotlin.reflect.KFunction
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
inline class S(val value: String?) {
operator fun plus(other: S): S = S(this.value!! + other.value!!)
}
object C {
@JvmStatic
fun foo(x: S, y: String, z: S?): S = x + S(y) + z!!
}
interface I {
companion object {
@JvmStatic
fun bar(x: String, y: S, z: S?): S = S(x) + y + z!!
}
}
fun box(): String {
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("abc"), C::foo.call(S("a"), "b", S("c")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("def"), (I)::bar.call("d", S("e"), S("f")))
}
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(S("ghi"), unboundFoo.call(C, S("g"), "h", S("i")))
}
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(S("jkl"), unboundBar.call(I, "j", S("k"), S("l")))
}
return "OK"
}
@@ -0,0 +1,45 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
inline class S(val x: String?) {
fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
inline class Z(val x: Int) {
fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
inline class A(val x: Any) {
fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
fun box(): String {
val plus = S("+")
val aster = S("*")
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", S::test.call(S("42"), "-", plus, aster))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", S("42")::test.call("-", plus, aster))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", Z::test.call(Z(42), "-", plus, aster))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", Z(42)::test.call("-", plus, aster))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", A::test.call(A("42"), "-", plus, aster))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", A("42")::test.call("-", plus, aster))
}
return "OK"
}
@@ -0,0 +1,149 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
var global = S("")
inline class S(val x: String?) {
var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
inline class Z(val x: Int) {
var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
inline class A(val x: Any) {
var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
fun box(): String {
global = S("")
assertEquals(S("42"), S::nonNullTest.call(S("42")))
assertEquals(S("42"), S("42")::nonNullTest.call())
assertEquals(S("42"), S::nonNullTest.getter.call(S("42")))
assertEquals(S("42"), S("42")::nonNullTest.getter.call())
S::nonNullTest.setter.call(S("42"), S("S-"))
assertEquals(S("S-42"), global)
S("42")::nonNullTest.setter.call(S("S+"))
assertEquals(S("S+42"), global)
global = S("")
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), S::nullableTest.call(S("42")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), S("42")::nullableTest.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), S::nullableTest.getter.call(S("42")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), S("42")::nullableTest.getter.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
S::nullableTest.setter.call(S("42"), S("S-"))
assertEquals(S("S-42"), global)
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
S("42")::nullableTest.setter.call(S("S+"))
assertEquals(S("S+42"), global)
}
global = S("")
assertEquals(S("42"), Z::nonNullTest.call(Z(42)))
assertEquals(S("42"), Z(42)::nonNullTest.call())
assertEquals(S("42"), Z::nonNullTest.getter.call(Z(42)))
assertEquals(S("42"), Z(42)::nonNullTest.getter.call())
Z::nonNullTest.setter.call(Z(42), S("Z-"))
assertEquals(S("Z-42"), global)
Z(42)::nonNullTest.setter.call(S("Z+"))
assertEquals(S("Z+42"), global)
global = S("")
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), Z::nullableTest.call(Z(42)))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), Z(42)::nullableTest.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), Z::nullableTest.getter.call(Z(42)))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), Z(42)::nullableTest.getter.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
Z::nullableTest.setter.call(Z(42), S("Z-"))
assertEquals(S("Z-42"), global)
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
Z(42)::nullableTest.setter.call(S("Z+"))
assertEquals(S("Z+42"), global)
}
global = S("")
assertEquals(S("42"), A::nonNullTest.call(A(42)))
assertEquals(S("42"), A(42)::nonNullTest.call())
assertEquals(S("42"), A::nonNullTest.getter.call(A(42)))
assertEquals(S("42"), A(42)::nonNullTest.getter.call())
A::nonNullTest.setter.call(A(42), S("A-"))
assertEquals(S("A-42"), global)
A(42)::nonNullTest.setter.call(S("A+"))
assertEquals(S("A+42"), global)
global = S("")
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), A::nullableTest.call(A(42)))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), A(42)::nullableTest.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), A::nullableTest.getter.call(A(42)))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), A(42)::nullableTest.getter.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
A::nullableTest.setter.call(A(42), S("A-"))
assertEquals(S("A-42"), global)
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
A(42)::nullableTest.setter.call(S("A+"))
assertEquals(S("A+42"), global)
}
return "OK"
}
@@ -0,0 +1,49 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
interface ITest {
fun test(a: String, b: S, c: S?): String
}
inline class S(val x: String?) : ITest {
override fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
inline class Z(val x: Int) : ITest {
override fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
inline class A(val x: Any) : ITest {
override fun test(a: String, b: S, c: S?) = "$x$a${b.x}${c!!.x}"
}
fun box(): String {
val plus = S("+")
val aster = S("*")
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", S::test.call(S("42"), "-", plus, aster))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", S("42")::test.call("-", plus, aster))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", Z::test.call(Z(42), "-", plus, aster))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", Z(42)::test.call("-", plus, aster))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", A::test.call(A("42"), "-", plus, aster))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals("42-+*", A("42")::test.call("-", plus, aster))
}
return "OK"
}
@@ -0,0 +1,154 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
var global = S("")
interface ITest {
var nonNullTest: S
var nullableTest: S?
}
inline class S(val x: String?) : ITest {
override var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
override var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
inline class Z(val x: Int) : ITest {
override var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
override var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
inline class A(val x: Any) : ITest {
override var nonNullTest: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
override var nullableTest: S?
get() = S("${global.x}$x")
set(value) {
global = S("${value!!.x}$x")
}
}
fun box(): String {
global = S("")
assertEquals(S("42"), S::nonNullTest.call(S("42")))
assertEquals(S("42"), S("42")::nonNullTest.call())
assertEquals(S("42"), S::nonNullTest.getter.call(S("42")))
assertEquals(S("42"), S("42")::nonNullTest.getter.call())
S::nonNullTest.setter.call(S("42"), S("S-"))
assertEquals(S("S-42"), global)
S("42")::nonNullTest.setter.call(S("S+"))
assertEquals(S("S+42"), global)
global = S("")
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), S::nullableTest.call(S("42")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), S("42")::nullableTest.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), S::nullableTest.getter.call(S("42")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), S("42")::nullableTest.getter.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
S::nullableTest.setter.call(S("42"), S("S-"))
assertEquals(S("S-42"), global)
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
S("42")::nullableTest.setter.call(S("S+"))
assertEquals(S("S+42"), global)
}
global = S("")
assertEquals(S("42"), Z::nonNullTest.call(Z(42)))
assertEquals(S("42"), Z(42)::nonNullTest.call())
assertEquals(S("42"), Z::nonNullTest.getter.call(Z(42)))
assertEquals(S("42"), Z(42)::nonNullTest.getter.call())
Z::nonNullTest.setter.call(Z(42), S("Z-"))
assertEquals(S("Z-42"), global)
Z(42)::nonNullTest.setter.call(S("Z+"))
assertEquals(S("Z+42"), global)
global = S("")
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), Z::nullableTest.call(Z(42)))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), Z(42)::nullableTest.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), Z::nullableTest.getter.call(Z(42)))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), Z(42)::nullableTest.getter.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
Z::nullableTest.setter.call(Z(42), S("Z-"))
assertEquals(S("Z-42"), global)
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
Z(42)::nullableTest.setter.call(S("Z+"))
assertEquals(S("Z+42"), global)
}
global = S("")
assertEquals(S("42"), A::nonNullTest.call(A(42)))
assertEquals(S("42"), A(42)::nonNullTest.call())
assertEquals(S("42"), A::nonNullTest.getter.call(A(42)))
assertEquals(S("42"), A(42)::nonNullTest.getter.call())
A::nonNullTest.setter.call(A(42), S("A-"))
assertEquals(S("A-42"), global)
A(42)::nonNullTest.setter.call(S("A+"))
assertEquals(S("A+42"), global)
global = S("")
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), A::nullableTest.call(A(42)))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), A(42)::nullableTest.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), A::nullableTest.getter.call(A(42)))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(S("42"), A(42)::nullableTest.getter.call())
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
A::nullableTest.setter.call(A(42), S("A-"))
assertEquals(S("A-42"), global)
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
A(42)::nullableTest.setter.call(S("A+"))
assertEquals(S("A+42"), global)
}
return "OK"
}
@@ -0,0 +1,135 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.reflect.KMutableProperty2
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
inline class S(val value: String?) {
operator fun plus(other: S): S = S(this.value!! + other.value!!)
}
class C {
var nonNullMember: S = S("")
var nullableMember: S? = S("")
private var suffix = S("")
var S.nonNull_nonNullMemExt: S
get() = this + suffix
set(value) { suffix = this + value }
var S.nonNull_nullableMemExt: S?
get() = this + suffix
set(value) { suffix = this + value!! }
var S?.nullable_nonNullMemExt: S
get() = this!! + suffix
set(value) { suffix = this!! + value }
var S?.nullable_nullableMemExt: S?
get() = this!! + suffix
set(value) { suffix = this!! + value!! }
}
var nonNullTopLevel: S = S("")
var nullableTopLevel: S? = S("")
private var suffix = S("")
var S.nonNull_nonNullExt: S
get() = this + suffix
set(value) { suffix = this + value }
var S.nonNull_nullableExt: S?
get() = this + suffix
set(value) { suffix = this + value!! }
var S?.nullable_nonNullExt: S
get() = this!! + suffix
set(value) { suffix = this!! + value }
var S?.nullable_nullableExt: S?
get() = this!! + suffix
set(value) { suffix = this!! + value!! }
fun box(): String {
val c = C()
assertEquals(Unit, C::nonNullMember.setter.call(c, S("ab")))
assertEquals(S("ab"), C::nonNullMember.call(c))
assertEquals(S("ab"), C::nonNullMember.getter.call(c))
assertEquals(Unit, c::nonNullMember.setter.call(S("cd")))
assertEquals(S("cd"), c::nonNullMember.call())
assertEquals(S("cd"), 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, S("ab")))
assertEquals(S("ab"), C::nullableMember.call(c))
assertEquals(S("ab"), 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(S("cd")))
assertEquals(S("cd"), c::nullableMember.call())
assertEquals(S("cd"), c::nullableMember.getter.call())
}
val nonNull_nonNullMemExt = C::class.members.single { it.name == "nonNull_nonNullMemExt" } as KMutableProperty2<C, S, S>
assertEquals(Unit, nonNull_nonNullMemExt.setter.call(c, S(""), S("f")))
assertEquals(S("ef"), nonNull_nonNullMemExt.call(c, S("e")))
assertEquals(S("ef"), nonNull_nonNullMemExt.getter.call(c, S("e")))
val nonNull_nullableMemExt = C::class.members.single { it.name == "nonNull_nullableMemExt" } as KMutableProperty2<C, S, S?>
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(Unit, nonNull_nullableMemExt.setter.call(c, S(""), S("f")))
assertEquals(S("ef"), nonNull_nullableMemExt.call(c, S("e")))
assertEquals(S("ef"), nonNull_nullableMemExt.getter.call(c, S("e")))
}
val nullable_nonNullMemExt = C::class.members.single { it.name == "nullable_nonNullMemExt" } as KMutableProperty2<C, S?, S>
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(Unit, nullable_nonNullMemExt.setter.call(c, S(""), S("f")))
assertEquals(S("ef"), nullable_nonNullMemExt.call(c, S("e")))
assertEquals(S("ef"), nullable_nonNullMemExt.getter.call(c, S("e")))
}
val nullable_nullableMemExt = C::class.members.single { it.name == "nullable_nullableMemExt" } as KMutableProperty2<C, S?, S?>
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(Unit, nullable_nullableMemExt.setter.call(c, S(""), S("f")))
assertEquals(S("ef"), nullable_nullableMemExt.call(c, S("e")))
assertEquals(S("ef"), nullable_nullableMemExt.getter.call(c, S("e")))
}
assertEquals(Unit, ::nonNullTopLevel.setter.call(S("gh")))
assertEquals(S("gh"), ::nonNullTopLevel.call())
assertEquals(S("gh"), ::nonNullTopLevel.getter.call())
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(Unit, ::nullableTopLevel.setter.call(S("gh")))
assertEquals(S("gh"), ::nullableTopLevel.call())
assertEquals(S("gh"), ::nullableTopLevel.getter.call())
}
assertEquals(Unit, S::nonNull_nonNullExt.setter.call(S(""), S("j")))
assertEquals(S("ij"), S::nonNull_nonNullExt.call(S("i")))
assertEquals(S("ij"), S::nonNull_nonNullExt.getter.call(S("i")))
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(Unit, S::nonNull_nullableExt.setter.call(S(""), S("j")))
assertEquals(S("ij"), S::nonNull_nullableExt.call(S("i")))
assertEquals(S("ij"), S::nonNull_nullableExt.getter.call(S("i")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(Unit, S?::nullable_nonNullExt.setter.call(S(""), S("j")))
assertEquals(S("ij"), S?::nullable_nonNullExt.call(S("i")))
assertEquals(S("ij"), S?::nullable_nonNullExt.getter.call(S("i")))
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
assertEquals(Unit, S?::nullable_nullableExt.setter.call(S(""), S("j")))
assertEquals(S("ij"), S?::nullable_nullableExt.call(S("i")))
assertEquals(S("ij"), S?::nullable_nullableExt.getter.call(S("i")))
}
return "OK"
}
@@ -0,0 +1,70 @@
// 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 S(val value: String?)
class C {
private var value: S = S("")
suspend fun nonNullConsume(z: S) { value = z }
suspend fun nonNullProduce(): S = value
suspend fun nullableConsume(z: S?) { value = z!! }
suspend fun nullableProduce(): S? = value
suspend fun nonNull_nonNullConsumeAndProduce(z: S): S = z
suspend fun nonNull_nullableConsumeAndProduce(z: S): S? = z
suspend fun nullable_nonNullConsumeAndProduce(z: S?): S = z!!
suspend fun nullable_nullableConsumeAndProduce(z: S?): S? = z
}
private fun run0(f: suspend () -> String): String {
var result = ""
f.startCoroutine(handleResultContinuation { result = it })
return result
}
fun box(): String {
val c = C()
run0 {
C::nonNullConsume.callSuspend(c, S("nonNull"))
C::nonNullProduce.callSuspend(c).value!!
}.let { assertEquals("nonNull", it) }
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
run0 {
C::nullableConsume.callSuspend(c, S("nullable"))
C::nullableProduce.callSuspend(c)!!.value!!
}.let { assertEquals("nullable", it) }
}
run0 {
C::nonNull_nonNullConsumeAndProduce.callSuspend(c, S("nonNull_nonNull")).value!!
}.let { assertEquals("nonNull_nonNull", it) }
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
run0 {
C::nonNull_nullableConsumeAndProduce.callSuspend(c, S("nonNull_nullable"))!!.value!!
}.let { assertEquals("nonNull_nullable", it) }
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
run0 {
C::nullable_nonNullConsumeAndProduce.callSuspend(c, S("nullable_nonNull")).value!!
}.let { assertEquals("nullable_nonNull", it) }
}
assertFailsWith<IllegalArgumentException>("Remove assertFailsWith and try again, as this problem may have been fixed.") {
run0 {
C::nullable_nullableConsumeAndProduce.callSuspend(c, S("nullable_nullable"))!!.value!!
}.let { assertEquals("nullable_nullable", it) }
}
return "OK"
}
@@ -1,40 +0,0 @@
// IGNORE_BACKEND: JS_IR, JS, NATIVE, WASM
// IGNORE_BACKEND: JS_IR_ES6
// WITH_REFLECT
import kotlin.test.assertEquals
interface ITest {
fun test(a: String, b: S): String
}
inline class Z(val x: Int) : ITest {
override fun test(a: String, b: S) = "$x$a${b.x}"
}
inline class L(val x: Long) : ITest {
override fun test(a: String, b: S) = "$x$a${b.x}"
}
inline class S(val x: String) : ITest {
override fun test(a: String, b: S) = "$x$a${b.x}"
}
inline class A(val x: Any) : ITest {
override fun test(a: String, b: S) = "$x$a${b.x}"
}
fun box(): String {
assertEquals("42-+", Z::test.call(Z(42), "-", S("+")))
assertEquals("42-+", Z(42)::test.call("-", S("+")))
assertEquals("42-+", L::test.call(L(42L), "-", S("+")))
assertEquals("42-+", L(42L)::test.call("-", S("+")))
assertEquals("42-+", S::test.call(S("42"), "-", S("+")))
assertEquals("42-+", S("42")::test.call("-", S("+")))
assertEquals("42-+", A::test.call(A("42"), "-", S("+")))
assertEquals("42-+", A("42")::test.call("-", S("+")))
return "OK"
}
@@ -1,86 +0,0 @@
// IGNORE_BACKEND: JS_IR, JS, NATIVE, WASM
// IGNORE_BACKEND: JS_IR_ES6
// WITH_REFLECT
import kotlin.test.assertEquals
var global = S("")
interface ITest {
var test: S
}
inline class Z(val x: Int) : ITest {
override var test: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
}
inline class L(val x: Long) : ITest {
override var test: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
}
inline class S(val x: String) : ITest {
override var test: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
}
inline class A(val x: Any) : ITest {
override var test: S
get() = S("${global.x}$x")
set(value) {
global = S("${value.x}$x")
}
}
fun box(): String {
global = S("")
assertEquals(S("42"), Z::test.call(Z(42)))
assertEquals(S("42"), Z(42)::test.call())
assertEquals(S("42"), Z::test.getter.call(Z(42)))
assertEquals(S("42"), Z(42)::test.getter.call())
Z::test.setter.call(Z(42), S("Z-"))
assertEquals(S("Z-42"), global)
Z(42)::test.setter.call(S("Z+"))
assertEquals(S("Z+42"), global)
global = S("")
assertEquals(S("42"), L::test.call(L(42L)))
assertEquals(S("42"), L(42L)::test.call())
assertEquals(S("42"), L::test.getter.call(L(42L)))
assertEquals(S("42"), L(42L)::test.getter.call())
L::test.setter.call(L(42L), S("L-"))
assertEquals(S("L-42"), global)
L(42L)::test.setter.call(S("L+"))
assertEquals(S("L+42"), global)
global = S("")
assertEquals(S("42"), S::test.call(S("42")))
assertEquals(S("42"), S("42")::test.call())
assertEquals(S("42"), S::test.getter.call(S("42")))
assertEquals(S("42"), S("42")::test.getter.call())
S::test.setter.call(S("42"), S("S-"))
assertEquals(S("S-42"), global)
S("42")::test.setter.call(S("S+"))
assertEquals(S("S+42"), global)
global = S("")
assertEquals(S("42"), A::test.call(A(42)))
assertEquals(S("42"), A(42)::test.call())
assertEquals(S("42"), A::test.getter.call(A(42)))
assertEquals(S("42"), A(42)::test.getter.call())
A::test.setter.call(A(42), S("A-"))
assertEquals(S("A-42"), global)
A(42)::test.setter.call(S("A+"))
assertEquals(S("A+42"), global)
return "OK"
}
@@ -10,8 +10,11 @@ inline class Z2(val x: Z)
inline class L(val x: Long)
inline class L2(val x: L)
inline class A(val x: Any?)
inline class A2(val x: A)
inline class A1(val x: Any?)
inline class A1_2(val x: A1)
inline class A2(val x: Any)
inline class A2_2(val x: A2)
fun box(): String {
assertEquals(42, Z::x.call(Z(42)))
@@ -20,10 +23,10 @@ fun box(): String {
assertEquals(1234L, L::x.call(L(1234L)))
assertEquals(1234L, L(1234L)::x.call())
assertEquals("abc", A::x.call(A("abc")))
assertEquals("abc", A("abc")::x.call())
assertEquals(null, A::x.call(A(null)))
assertEquals(null, A(null)::x.call())
assertEquals("abc", A1::x.call(A1("abc")))
assertEquals("abc", A1("abc")::x.call())
assertEquals(null, A1::x.call(A1(null)))
assertEquals(null, A1(null)::x.call())
assertEquals(Z(42), Z2::x.call(Z2(Z(42))))
assertEquals(Z(42), Z2(Z(42))::x.call())
@@ -31,10 +34,12 @@ fun box(): String {
assertEquals(L(1234L), L2::x.call(L2(L(1234L))))
assertEquals(L(1234L), L2(L(1234L))::x.call())
assertEquals(A("abc"), A2::x.call(A2(A("abc"))))
assertEquals(A("abc"), A2(A("abc"))::x.call())
assertEquals(A(null), A2::x.call(A2(A(null))))
assertEquals(A(null), A2(A(null))::x.call())
assertEquals(A1("abc"), A1_2::x.call(A1_2(A1("abc"))))
assertEquals(A1("abc"), A1_2(A1("abc"))::x.call())
assertEquals(A1(null), A1_2::x.call(A1_2(A1(null))))
assertEquals(A1(null), A1_2(A1(null))::x.call())
assertEquals(A2("abc"), A2_2::x.call(A2_2(A2("abc"))))
assertEquals(A2("abc"), A2_2(A2("abc"))::x.call())
return "OK"
}
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -1,52 +0,0 @@
// IGNORE_BACKEND: JS_IR, JS, NATIVE, WASM
// IGNORE_BACKEND: JS_IR_ES6
// WITH_REFLECT
import kotlin.reflect.KMutableProperty2
import kotlin.test.assertEquals
inline class S(val value: String) {
operator fun plus(other: S): S = S(this.value + other.value)
}
class C {
var member: S = S("")
private var suffix = S("")
var S.memExt: S
get() = this + suffix
set(value) { suffix = this + value }
}
var topLevel: S = S("")
private var suffix = S("")
var S.ext: S
get() = this + suffix
set(value) { suffix = this + value }
fun box(): String {
val c = C()
assertEquals(Unit, C::member.setter.call(c, S("ab")))
assertEquals(S("ab"), C::member.call(c))
assertEquals(S("ab"), C::member.getter.call(c))
assertEquals(Unit, c::member.setter.call(S("cd")))
assertEquals(S("cd"), c::member.call())
assertEquals(S("cd"), c::member.getter.call())
val memExt = C::class.members.single { it.name == "memExt" } as KMutableProperty2<C, S, S>
assertEquals(Unit, memExt.setter.call(c, S(""), S("f")))
assertEquals(S("ef"), memExt.call(c, S("e")))
assertEquals(S("ef"), memExt.getter.call(c, S("e")))
assertEquals(Unit, ::topLevel.setter.call(S("gh")))
assertEquals(S("gh"), ::topLevel.call())
assertEquals(S("gh"), ::topLevel.getter.call())
assertEquals(Unit, S::ext.setter.call(S(""), S("j")))
assertEquals(S("ij"), S::ext.call(S("i")))
assertEquals(S("ij"), S::ext.getter.call(S("i")))
return "OK"
}
@@ -1,34 +0,0 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
// WITH_COROUTINES
package test
import kotlin.coroutines.startCoroutine
import kotlin.reflect.full.callSuspend
import helpers.*
inline class Z(val value: String)
class S {
private var value: Z = Z("")
suspend fun consumeZ(z: Z) { value = z }
suspend fun produceZ(): Z = value
suspend fun consumeAndProduceZ(z: Z): Z = z
}
private fun run0(f: suspend () -> String): String {
var result = ""
f.startCoroutine(handleResultContinuation { result = it })
return result
}
fun box(): String =
run0 {
val s = S()
S::consumeZ.callSuspend(s, Z("z"))
val v = S::produceZ.callSuspend(s)
if (v != Z("z")) "Fail: $v"
else S::consumeAndProduceZ.callSuspend(s, Z("OK")).value
}