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
This commit is contained in:
Dmitry Petrov
2017-02-15 11:36:49 +03:00
parent ec403bfdbc
commit a087ea559f
8 changed files with 91 additions and 5 deletions

View File

@@ -20,4 +20,4 @@ fun bar() {
// 0 valueOf
// 0 Value\s\(\)
// 2 INSTANCEOF
// 2 CHECKCAST
// 1 CHECKCAST

View File

@@ -0,0 +1,12 @@
interface WorldObject {
val name: String
}
fun testB(worldObj: WorldObject) {
val y = worldObj.let {
println("object name: ${it.name}")
it
}
}
// 0 CHECKCAST

View File

@@ -0,0 +1,3 @@
fun <T> f(o: Any): T = o as T
// 0 CHECKCAST