Files
kotlin/compiler/testData/codegen/box/inlineClasses/boundCallableReferencePassedToInlineFunction.kt
Ilmir Usmanov 741c1a864f JVM_IR: IC: Unbox inline class argument of callable reference
if it is unbound and the underlying type is reference type.
If the underlying type is primitive, it is boxed and unboxed
correctly, otherwise, it is simply casted and not unboxed.
Additionally, generate functions for inliner with inline classes
in signature, so unboxing works.
The unboxing is removed after inlining.
 #KT-44722 Fixed
2021-02-18 18:31:48 +01:00

65 lines
1.8 KiB
Kotlin
Vendored

// WITH_RUNTIME
inline class IcInt(val i: Int) {
fun simple(): String = i.toString()
}
inline class IcLong(val l: Long) {
fun simple(): String = l.toString()
}
inline class IcAny(val a: Any?) {
fun simple(): String = a?.toString() ?: "null"
}
inline class IcOverIc(val o: IcLong) {
fun simple(): String = o.toString()
}
fun testUnboxed(i: IcInt, l: IcLong, a: IcAny, o: IcOverIc): String =
foo(i::simple) + foo(l::simple) + foo(a::simple) + foo(o::simple)
fun testBoxed(i: IcInt?, l: IcLong?, a: IcAny?, o: IcOverIc?): String =
foo(i!!::simple) + foo(l!!::simple) + foo(a!!::simple) + foo(o!!::simple)
fun testLocalVars(): String {
val i = IcInt(0)
val l = IcLong(1L)
val a = IcAny(2)
val o = IcOverIc(IcLong(3))
return foo(i::simple) + foo(l::simple) + foo(a::simple) + foo(o::simple)
}
val ip = IcInt(1)
val lp = IcLong(2L)
val ap = IcAny(3)
val op = IcOverIc(IcLong(4))
fun testGlobalProperties(): String =
foo(ip::simple) + foo(lp::simple) + foo(ap::simple) + foo(op::simple)
fun testCapturedVars(): String {
return IcInt(2).let { foo(it::simple) } +
IcLong(3).let { foo(it::simple) } +
IcAny(4).let { foo(it::simple) } +
IcOverIc(IcLong(5)).let { foo(it::simple) }
}
inline fun foo(init: () -> String): String = init()
fun box(): String {
val i = IcInt(3)
val l = IcLong(4)
val a = IcAny(5)
val o = IcOverIc(IcLong(6))
if (testUnboxed(i, l, a, o) != "345IcLong(l=6)") return "Fail 1 ${testUnboxed(i, l, a, o)}"
if (testBoxed(i, l, a, o) != "345IcLong(l=6)") return "Fail 2"
if (testLocalVars() != "012IcLong(l=3)") return "Fail 3"
if (testGlobalProperties() != "123IcLong(l=4)") return "Fail 4"
if (testCapturedVars() != "234IcLong(l=5)") return "Fail 5 ${testCapturedVars()}"
return "OK"
}