Files
pyos 34878d17eb JVM: be more careful when removing unused constants
1. if an argument of a `pop` cannot be removed, then all other potential
   arguments of that `pop` can't be removed either, and the same applies
   to other `pop`s that touch them;
2. the same is true for primitive conversions, but this is even trickier
   to implement correctly, so I simply did the same thing as with
   boxing operators: replace the conversion itself with a `pop` and keep
   the argument as-is.

Somehow this actually removes *more* redundant primitive type conversions
than the old code in a couple bytecode text tests, so I've patched them
to kind of use the value, forcing the instructions to stay.

 #KT-46921 Fixed
2021-05-27 12:24:22 +02:00

23 lines
433 B
Kotlin
Vendored

inline fun <R, T> foo(x : R?, block : (R?) -> T) : T {
return block(x)
}
fun bar() {
val a = foo(1) { x -> x!!.toLong() }
val b = foo(1) { x -> x!!.toShort() }
val c = foo(1L) { x -> x!!.toByte() }
val d = foo(1L) { x -> x!!.toShort() }
val e = foo('a') { x -> x!!.toDouble() }
val f = foo(1.0) { x -> x!!.toInt() }
}
// 0 valueOf
// 0 Value\s\(\)
// 1 I2L
// 2 L2I
// 2 I2S
// 1 I2B
// 1 I2D
// 1 D2I