Is it just because it's too difficult for the compiler to figure out that it is in fact exhaustive?
d
dmitriy.novozhilov
07/22/2022, 2:52 PM
Yes, it's too difficult
For compiler
Pair
is just a regular class, like anyone else
👍 2
c
Casey Brooks
07/22/2022, 2:57 PM
What you’re thinking of is Pattern Matching, which is not supported yet, though there’s been discussions on it for a while (see https://youtrack.jetbrains.com/issue/KT-186). It’s a very complicated language feature, and the Kotlin team has never (to my knowledge) committed to actually implementing it, though they haven’t said “no” to it either. Kind of in a limbo where we may get it eventually, but don’t hold your breath waiting for it.
The thing I typically do in this kind of case is just throw an
else -> error("will never happen")
line in the when, knowing that the equality checks will be exhaustive even if the compiler cannot figure it out
m
mbonnin
07/22/2022, 3:14 PM
There was a nice article sometime ago that was diving into that and how difficult it was. Can't find it anymore but maybe someone reading this will?