https://kotlinlang.org logo
Title
b

bod

10/04/2018, 11:55 AM
Hello, World! I’m in a
when (e)
, (with e being an instance of
MyEnum
) and for the branches, I’m allowed to put something that is not one of the possible values of
MyEnum
(I can put values of other enums). I find this extremely surprising 🙂 Thoughts?
h

Hamza

10/04/2018, 11:56 AM
can u show us an example
a

arekolek

10/04/2018, 11:57 AM
yeah it would be nice to have at least a warning that this is an unreachable branch
b

bod

10/04/2018, 11:57 AM
when (transaction.status) {
                    TransactionStatus.PENDING -> TODO()
                    TransactionStatus.COMPLETED -> TODO()
                    TransactionStatus.DECLINED -> TODO()
                    TransactionStatus.UNKNOWN -> TODO()
                    TransactionActivityTag.TRANSPORT -> TODO()
a

arekolek

10/04/2018, 11:57 AM
(or maybe it’s not actually unreachable)
b

bod

10/04/2018, 11:57 AM
compiles
h

Hamza

10/04/2018, 11:58 AM
is there any warnings?
b

bod

10/04/2018, 11:58 AM
nope
how come I’m not allowed to put, say, a
String
but another type that happens to be an enum. I’m allowed?
a

arekolek

10/04/2018, 12:02 PM
I remembered there was a similar discussion https://kotlinlang.slack.com/archives/C0922A726/p1530087621000037
b

bod

10/04/2018, 12:04 PM
wow 😱
ok,
when
on `enum`s is broken in Kotlin 😄 Not scary at all!
oh wait it says it’s fixed 🙂 https://youtrack.jetbrains.net/issue/KT-24708
(we’re not on 1.3 yet)
a

arekolek

10/04/2018, 12:14 PM
and this one https://youtrack.jetbrains.net/issue/KT-22043 looks like what would fix the thing you originally mentioned
👍 1
b

bod

10/04/2018, 12:16 PM
(in my case, we have the same value name in 2 enums, and I “static import” them both - hilarity ensued)
😱 1
m

Mike

10/04/2018, 1:10 PM
The when is much more strict if the result is used. Still an issue here that may be addressed. Would be curious to know what happens if you assign the when to a variable.
a

arekolek

10/04/2018, 1:27 PM
Same thing happens
😱 1