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
@@ -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"
}