Files
kotlin-fork/compiler/testData/codegen/box/boxingOptimization/kClassEquals.kt
T
Dmitry Petrov 61faa068d4 Do not optimize == for KClasses in redundant boxing elimination
For primitive wrappers such as java.lang.Integer,
  jlc = java.lang.Integer.class
  jlt = java.lang.Integer.TYPE
  !(ljc.equals(ljt))
However, in Kotlin corresponding KClass instances are equal.

 #KT-17748 Fixed Target versions 1.1.50
 #KT-17879 Fixed Target versions 1.1.50
2017-09-06 09:54:36 +03:00

20 lines
395 B
Kotlin
Vendored

// IGNORE_BACKEND: JS, NATIVE
fun test(a: Any) = when (a::class) {
String::class -> "String"
Int::class -> "Int"
Boolean::class -> "Boolean"
else -> "Else"
}
fun box(): String {
val s = ""
val i = 0
val b = false
if (test(s) != "String") return "Fail 1"
if (test(i) != "Int") return "Fail 2"
if (test(b) != "Boolean") return "Fail 3"
return "OK"
}