https://kotlinlang.org logo
#announcements
Title
# announcements
l

LastExceed

09/02/2019, 6:24 AM
Copy code
fun main() {
    val x = Thing(42)
    when(x) {
        Thing(42) -> {
            println("foo")
        }
        else -> {
            println("bar")
        }
    }
}

inline class Thing(val value: Int)
the output is
foo
IntelliJ suggests inlining
x
, like so:
Copy code
fun main() {
    when(val x = Thing(42)) {
        Thing(42) -> {
            println("foo")
        }
        else -> {
            println("bar")
        }
    }
}

inline class Thing(val value: Int)
however now it outputs
bar
. why is that?
k

karelpeeters

09/02/2019, 6:45 AM
That has to be a compiler bug I think, report on youtrack.
e

Eugen Martynov

09/02/2019, 8:18 AM
Can you check decompiled code?
I wonder if it is int or Integer after inlining
👆 1
w

wasyl

09/02/2019, 8:45 AM
Can you declare type for the inlined
val
? Would
val x: Thing = Thing(42)
work as expected?
s

streetsofboston

09/02/2019, 1:51 PM
For some reason, it looks like one example is auto-boxed into a 'Thing' and the other example remains inlined, like an 'Int'. No idea why.... Looks like a bug... or at least super confusing...
2 Views