Files
kotlin/compiler/testData/codegen/box/when/enumOptimization/kt14802.kt
2019-11-19 11:00:09 +03:00

29 lines
610 B
Kotlin
Vendored

// IGNORE_BACKEND_FIR: JVM_IR
// CHECK_CASES_COUNT: function=crash count=2
// CHECK_IF_COUNT: function=crash count=1
class EncapsulatedEnum<T : Enum<T>>(val value: T)
enum class MyEnum(val value: String) {
VALUE_A("OK"),
VALUE_B("fail"),
}
private fun crash(encapsulated: EncapsulatedEnum<*>) {
val myEnum = encapsulated.value
if (myEnum !is MyEnum) {
return
}
when (myEnum) {
MyEnum.VALUE_A -> res = myEnum.value
MyEnum.VALUE_B -> res = myEnum.value
}
}
var res = "fail"
fun box(): String {
crash(EncapsulatedEnum(MyEnum.VALUE_A))
return res
}