a revision that clearly spells out the rules for pattern matching should be drafted
I feel like the examples in the acceptance rational is a good jump off point. Quoting the full example here:
enum E {
case often(first: Int, second: Int)
case lots(first: Int, second: Int)
case many(value: Int)
case many(first: Int, second: Int)
case many(alpha: Int, beta: Int)
case sometimes(value: Int)
case sometimes(Int)
}
switch e {
// Valid: the sequence of labels exactly matches a case name.
case .often(first: let a, second: let b):
...
// Valid: there is only one case with this base name.
case .lots(let a, let b):
...
// Valid: there is only one case with this base name and payload count.
case .many(let a):
...
// Invalid: there are multiple cases with this base name and payload count.
case .many(let a, let b):
...
// Valid: the sequence of labels exactly matches a case name.
case .many(first: let a, second: let b):
...
// Invalid: includes a label, but not on all of the labelled arguments.
case .same(alpha: let a, let b):
...
// Valid: the sequence of labels exactly matches a case name (that happens to not provide any labels).
case .sometimes(let x):
...
// Invalid: includes a label, but there is no matching case.
case .sometimes(badlabel: let x):
...
}
When we left our last discussion, there seems to be some different intepretation on this sentence in the rationale,
A case pattern may omit labels for the associated values of a case if there is only one case with the same base name and arity.
@codafi said:
If we’re matching by arity, the labels go out the door;
… and @anandabits replied with:
That’s not how I read it: "A pattern must omit all labels if it omits any of them; thus, a case pattern either exactly matches the full name of a case or has no labels at all."
It seems to me the disagreement whether the following should be valid:
/// (?) This is a unique basename + arity case. We can omit label `value`
/// but should including it be valid too?
case .many(value: let a):
Is this the focal point of that discussion?