Don't remap inline function args requiring inline class boxing/unboxing

Same as for primitives: inline lambda expects to see a boxed value,
so, even if an argument is a local variable, it can't be remapped,
because it contains unboxed representation.
This commit is contained in:
Dmitry Petrov
2018-08-23 18:09:14 +03:00
parent 6e2d05cd94
commit 2a524920a5
10 changed files with 200 additions and 6 deletions
@@ -0,0 +1,32 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class Z(val int: Int)
inline class L(val long: Long)
inline class Str(val string: String)
inline class Obj(val obj: Any)
inline fun <R> withDefaultZ(fn: (Z) -> R, x: Z = Z(42)) = fn(x)
inline fun <R> withDefaultL(fn: (L) -> R, x: L = L(42L)) = fn(x)
inline fun <R> withDefaultL2(x: L = L(42L), fn: (L) -> R) = fn(x)
inline fun <R> withDefaultStr(fn: (Str) -> R, x: Str = Str("abc")) = fn(x)
inline fun <R> withDefaultObj(fn: (Obj) -> R, x: Obj = Obj("abc")) = fn(x)
inline fun <R> withDefaultObj2(x: Obj = Obj("abc"), fn: (Obj) -> R) = fn(x)
fun testWithDefaultZ() = withDefaultZ({ Z(it.int + 1) })
fun testWithDefaultL() = withDefaultL({ L(it.long + 1L) })
fun testWithDefaultL2() = withDefaultL2(fn = { L(it.long + 1L) })
fun testWithDefaultStr() = withDefaultStr({ Str(it.string + "1") })
fun testWithDefaultObj() = withDefaultObj({ Obj(it.obj.toString() + "1") })
fun testWithDefaultObj2() = withDefaultObj2(fn = { Obj(it.obj.toString() + "1") })
fun box(): String {
if (testWithDefaultZ().int != 43) throw AssertionError()
if (testWithDefaultL().long != 43L) throw AssertionError()
if (testWithDefaultL2().long != 43L) throw AssertionError()
if (testWithDefaultStr().string != "abc1") throw AssertionError()
if (testWithDefaultObj().obj != "abc1") throw AssertionError()
if (testWithDefaultObj2().obj != "abc1") throw AssertionError()
return "OK"
}
@@ -0,0 +1,26 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class Z(val int: Int)
inline class L(val long: Long)
inline class Str(val string: String)
inline class Obj(val obj: Any)
inline fun <R> s1Z(x: Z, fn: (Int, Z) -> R) = fn(1, x)
inline fun <R> s1L(x: L, fn: (Int, L) -> R) = fn(1, x)
inline fun <R> s1Str(x: Str, fn: (Int, Str) -> R) = fn(1, x)
inline fun <R> s1Obj(x: Obj, fn: (Int, Obj) -> R) = fn(1, x)
fun testS1Z(a: Z) = s1Z(a) { i, xx -> Z(xx.int + i) }
fun testS1L(a: L) = s1L(a) { i, xx -> L(xx.long + i.toLong()) }
fun testS1Str(a: Str) = s1Str(a) { i, xx -> Str(xx.string + i.toString()) }
fun testS1Obj(a: Obj) = s1Obj(a) { i, xx -> Obj(xx.obj.toString() + i.toString()) }
fun box(): String {
if (testS1Z(Z(42)).int != 43) throw AssertionError()
if (testS1L(L(42L)).long != 43L) throw AssertionError()
if (testS1Str(Str("abc")).string != "abc1") throw AssertionError()
if (testS1Obj(Obj("abc")).obj != "abc1") throw AssertionError()
return "OK"
}
@@ -0,0 +1,25 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND: JVM_IR
inline class Str(val string: String)
inline class Obj(val obj: Any)
inline fun <T, R> s0(x: T, fn: (Int, T) -> R) = fn(0, x)
inline fun <T, R> weirdMix(x: T, fn: (Int, T, Long, T) -> R) = fn(0, x, 0L, x)
fun testS0Str(x: Str) = s0(x) { _, xx -> Str(xx.string + "123") }
fun testS0Any(x: Obj) = s0(x) { _, xx -> Obj(xx.obj.toString() + "123") }
fun testWeirdMixStr(x: Str) = weirdMix(x) { _, xx, _, _ -> Str(xx.string + "123") }
fun testWeirdMixAny(x: Obj) = weirdMix(x) { _, xx, _, _ -> Obj(xx.obj.toString() + "123") }
fun box(): String {
if (testS0Str(Str("abc")).string != "abc123") throw AssertionError()
if (testS0Any(Obj("abc")).obj != "abc123") throw AssertionError()
if (testWeirdMixStr(Str("abc")).string != "abc123") throw AssertionError()
if (testWeirdMixAny(Obj("abc")).obj != "abc123") throw AssertionError()
return "OK"
}