Stefan Beyer
07/30/2019, 1:01 PMfun foo(a: Boolean, b: Boolean) = when { // "when expression must be exhaustive" error
a == b -> "same"
a -> "first"
b -> "second"
// this actually IS exhaustive:
// a | b | result
// ---+---+--------
// 0 | 0 | same
// 1 | 0 | first
// 0 | 1 | second
// 1 | 1 | same
}
Do you guys think this is an issue that should be reported? 🙂
edit: I am not sure because surely this is just one example of a whole bunch of those cases and I personally would not want to implement thousands of corner cases into a language feature. (After all, this is a language, not platformer physics 😄)Spike Baylor
07/30/2019, 1:06 PMJan Stoltman
07/30/2019, 1:08 PMfalse, false
is equal to true, true
Stefan Beyer
07/30/2019, 1:11 PMwhen
does not care what a
and b
are... In this case they are final fields, but they could have been custom properties with getters that change their return value every time...Spike Baylor
07/30/2019, 1:13 PMStefan Beyer
07/30/2019, 1:14 PMkarelpeeters
07/30/2019, 1:34 PMwhen
smarter for cases like this. I'd be happy if they did, but in the end it's a choice they made.Dominaezzz
07/30/2019, 1:35 PMkarelpeeters
07/30/2019, 1:36 PMDominaezzz
07/30/2019, 1:36 PMSpike Baylor
07/30/2019, 1:50 PMclass Bar(val a: Boolean) {
fun foo(b: Boolean, c: Boolean) = when {
a -> "a!"
b == c -> "same"
b -> "first"
c -> "second"
}
}
karelpeeters
07/30/2019, 1:53 PMwhen((a, b)) {
(x, x) -> "same"
(true, _) -> "first"
(_, true) -> "second"
}
That solves the context problem but there's still SAT.Spike Baylor
07/30/2019, 1:53 PMkarelpeeters
07/30/2019, 1:54 PMSpike Baylor
07/30/2019, 1:56 PMkarelpeeters
07/30/2019, 1:57 PM(true, false)
would match the second one but not the first one.Spike Baylor
07/30/2019, 1:57 PMkarelpeeters
07/30/2019, 1:59 PMSpike Baylor
07/30/2019, 1:59 PMkarelpeeters
07/30/2019, 2:00 PMSpike Baylor
07/30/2019, 2:01 PMkarelpeeters
07/30/2019, 2:02 PM