Sorry if this has already been addressed, but is i...
# language-evolution
r
Sorry if this has already been addressed, but is it possible to eliminate the
condition is always true
warning for a final
when
clause? Here's an example:
Copy code
when { // This is flagged as requiring the else clause
    myInt < CONSTANT_INT -> {}
    myInt > CONSTANT_INT -> {}
    myInt == CONSTANT_INT -> {}  // This is flagged with an 'always true' warning
}
Is it possible to determine that this
when
is actually complete (as when covering all algebraic type cases) instead of demanding the
else
syntax? Edit: To be clear, I'm curious about whether this is feasible as a language feature.
👍 1
👍🏻 1
s
This is probably the ticket to watch: https://youtrack.jetbrains.com/issue/KT-63696
🙏 1
r
Thanks so much!
k
Perhaps we could have something like this:
Copy code
when { // This is flagged as requiring the else clause
    myInt < CONSTANT_INT -> doA()
    myInt > CONSTANT_INT -> doB()
    else myInt == CONSTANT_INT -> doC()
}
as syntactic sugar for this:
Copy code
when { // This is flagged as requiring the else clause
    myInt < CONSTANT_INT -> doA()
    myInt > CONSTANT_INT -> doB()
    else -> check(myInt == CONSTANT_INT) { "else clause in when statement failed check" }; doC()
}