LYR-SEM0032
or-pattern alternatives that bind differently
The alternatives of an or-pattern p | q do not bind the same names, or bind one name at different types.
Explanation
The arm after an or-pattern runs whichever alternative matched, so each name it uses must be bound by every alternative, and with one type.
Bind the same names in every alternative, or split the alternatives into separate arms.
Wrong
enum Pair { A(int), B(int) }
fn value(p: Pair): int {
return match (p) { .A(x) | .B(y) => 1 };
}
fn main(): void {
let _ = value(Pair.A(1));
}
Right
enum Pair { A(int), B(int) }
fn value(p: Pair): int {
return match (p) { .A(_) | .B(_) => 1 };
}
fn main(): void {
let _ = value(Pair.A(1));
}