Skip to content
Playground(another site)

bynk.types.or_pattern_type_mismatch

Error An or-pattern's alternatives give a shared binding different types (or refinements).

An or-pattern, A(n) | B(n), runs one arm for either alternative, so a name it binds must mean the same thing in both: the arm's body has only one n to use. Here n is an Int in one alternative and a String in the other, so the body could not be checked. A refined type and its base count as different too. Give each alternative its own arm, or bind a value of the same type in both.

Example

type Key = | Id(n: Int) | Name(n: String)
fn show(k: Key) -> String {
match k {
Id(n) | Name(n) => "key" // ✗ `n` is an `Int` and a `String`
}
}
fn show(k: Key) -> String {
match k {
Id(n) => "id" // ✓ one arm each
Name(n) => n
}
}

In the Book

See also

  • The grammar rules it governs: match_arm, is_expr.
  • Every code in its category, Type checking, on the diagnostic index.
  • bynk explain bynk.types.or_pattern_type_mismatch shows the same from the installed toolchain, without a network.