Correct boxing for functional types containing inline classes
This commit is contained in:
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class UInt(val value: Int)
|
||||
inline class ULong(val value: Long)
|
||||
|
||||
fun foo(u: UInt, f: (UInt) -> ULong): ULong = f(u)
|
||||
inline fun inlinedFoo(u: UInt, f: (UInt) -> ULong): ULong = f(u)
|
||||
|
||||
fun mapUIntToULong(u: UInt): ULong = ULong(u.value.toLong())
|
||||
|
||||
fun box(): String {
|
||||
val u = UInt(123)
|
||||
val l1 = foo(u) {
|
||||
mapUIntToULong(it)
|
||||
}
|
||||
|
||||
if (l1.value != 123L) return "fail"
|
||||
|
||||
val l2 = inlinedFoo(UInt(10)) {
|
||||
mapUIntToULong(it)
|
||||
}
|
||||
|
||||
if (l2.value != 10L) return "fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class UInt(val value: Int)
|
||||
inline class ULong(val value: Long)
|
||||
|
||||
fun foo(u: UInt, f: (UInt) -> ULong): ULong = f(u)
|
||||
|
||||
fun takeUInt(u: UInt) {}
|
||||
|
||||
fun test() {
|
||||
val u = UInt(0)
|
||||
val l = foo(u) { // box unbox UInt
|
||||
takeUInt(it)
|
||||
|
||||
ULong(0) // box ULong
|
||||
} // unbox ULong
|
||||
}
|
||||
|
||||
// 1 INVOKESTATIC UInt\$Erased.box
|
||||
// 1 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
// 1 INVOKESTATIC ULong\$Erased.box
|
||||
// 1 INVOKEVIRTUAL ULong.unbox
|
||||
|
||||
// 0 valueOf
|
||||
// 0 intValue
|
||||
// 0 longValue
|
||||
Reference in New Issue
Block a user