I was wondering if the compiler is supposed to opt...
# announcements
u
I was wondering if the compiler is supposed to optimize away the following `when`:
Copy code
typealias NumberType = Double

inline fun Number.toNumberType() = when (NumberType::class) {
    Double::class -> this.toDouble() as NumberType
    Float::class -> this.toFloat() as NumberType
    Long::class -> this.toLong() as NumberType
    Int::class -> this.toInt() as NumberType
    Short::class -> this.toShort() as NumberType
    Byte::class -> this.toByte() as NumberType
    else -> throw IllegalArgumentException("NumberType must be in [Double, Float, Long, Int, Short, Byte]")
}
Looking at the decompiled java code, it generates all
when
branches, not noticing, that only one will ever be selected. Is this expected or should i report?
➕ 1