Use proper KotlinType in get/set methods for property reference
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
inline class Z(val int: Int)
|
||||
|
||||
inline class Str(val string: String)
|
||||
|
||||
inline class NStr(val string: String?)
|
||||
|
||||
fun fooZ(x: Z) = x
|
||||
|
||||
fun fooStr(x: Str) = x
|
||||
|
||||
fun fooNStr(x: NStr) = x
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val fnZ = ::fooZ
|
||||
if (fnZ.invoke(Z(42)).int != 42) throw AssertionError()
|
||||
|
||||
val fnStr = ::fooStr
|
||||
if (fnStr.invoke(Str("str")).string != "str") throw AssertionError()
|
||||
|
||||
val fnNStr = ::fooNStr
|
||||
if (fnNStr.invoke(NStr(null)).string != null) throw AssertionError()
|
||||
if (fnNStr.invoke(NStr("nstr")).string != "nstr") throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
inline class Foo(val z: String)
|
||||
|
||||
var f = Foo("zzz")
|
||||
|
||||
fun box(): String {
|
||||
(::f).set(Foo("OK"))
|
||||
return (::f).get().z
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.reflect.KMutableProperty0
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
operator fun <R> KMutableProperty0<R>.setValue(host: Any?, property: KProperty<*>, value: R) = set(value)
|
||||
operator fun <R> KMutableProperty0<R>.getValue(host: Any?, property: KProperty<*>): R = get()
|
||||
|
||||
inline class Foo(val i: Int)
|
||||
|
||||
var f = Foo(4)
|
||||
|
||||
fun modify(ref: KMutableProperty0<Foo>) {
|
||||
var a by ref
|
||||
a = Foo(1)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
modify(::f)
|
||||
if (f.i != 1) throw AssertionError()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user