KT-37986 Force boxing of inline class returned from function reference

KT-37998 Provide KotlinType for safe call
This commit is contained in:
Dmitry Petrov
2020-04-03 16:31:00 +03:00
parent 5ed845d0b4
commit d5ace43614
11 changed files with 131 additions and 16 deletions
@@ -0,0 +1,25 @@
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
inline class R(val x: Any)
fun useR(r: R) {
if (r.x as String != "OK") throw AssertionError("$r")
}
fun useR0(fn: () -> R) {
useR(fn())
}
fun useR1(r: R, fn: (R) -> R) {
useR(fn(r))
}
fun fnWithDefaultR(r: R = R("OK")) = r
fun box(): String {
useR0(::fnWithDefaultR)
useR1(R("OK"), ::fnWithDefaultR)
return "OK"
}
+13
View File
@@ -0,0 +1,13 @@
inline class Z(val x: Int)
class A {
fun foo() = Z(42)
}
fun test(a: A?) = a?.foo()!!
fun box(): String {
val t = test(A())
if (t.x != 42) throw AssertionError("$t")
return "OK"
}