Files
kotlin/compiler/testData/codegen/bytecodeText/boxingOptimization/checkcastAndInstanceOf.kt
Dmitry Petrov a087ea559f Eliminate redundant CHECKCAST instructions
CHECKCAST is redundant if the corresponding static type exactly matches the target type.
CHECKCAST instructions to-be-reified should not be eliminated.

KT-14811 Unnecessary checkcast generated in parameterized functions
KT-14963 unnecessary checkcast java/lang/Object
2017-03-13 09:04:31 +03:00

24 lines
357 B
Kotlin
Vendored

inline fun <R, T> foo(x : R, y : R, block : (R) -> T) : T {
val a = x is Number
val b = x is Object
val a1 = x as Number
val b1 = x as Object
if (a && b) {
return block(x)
} else {
return block(y)
}
}
fun bar() {
foo(1, 2) { x -> x is Int }
}
// 0 valueOf
// 0 Value\s\(\)
// 2 INSTANCEOF
// 1 CHECKCAST