rook
10/04/2024, 3:34 PMcondition is always true
warning for a final when
clause? Here's an example:
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.Sam
10/04/2024, 3:43 PMrook
10/04/2024, 3:50 PMKlitos Kyriacou
10/07/2024, 4:12 PMwhen { // 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:
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()
}