I believe it’s because the case
evaluation has to return a Bool
i.e case foo
and case foo where foo.bar
evaluates to a true
/false
value which is used to decide whether the match is successful or not. I suppose an optional binding (where let a = b
) could be supported by treating it as a Bool
, however if you really want to do optional binding, the only way to do it now would be inside the case
statement:
// For convenience.
func other() -> Self {
return .other(type: type, value: value)
}
switch type {
case “validUntil”:
if let value = parseDate(value) {
self = .validUntil(value)
} else {
self = other()
}
...
}