E4082

E4082#

Variable is not bound in all patterns.

When using the | operator in a pattern, all variables must be bound in all patterns. If a variable were not bound in all patterns, it would be a free variable when the pattern is matched, which is not allowed.

Erroneous Example#

///|
priv enum E {
  A(Int, Double)
  B(Int)
}

///|
fn f(value : E) -> Unit {
  match value {
    A(a, _) | B(_) => println(a)
  }
}

Suggestion#

///|
priv enum  {
  (, )
  ()
}

///|
fn ( : ) ->  {
  match  {
    (, _) | () => ()
  }
}

///|
fn ( : ) ->  {
  match  {
    (_, ) => ()
    (_) => ()
  }
}

///|
test {
  ((1, 2.0))
  ((1))
  ((1, 2.0))
}