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 E {
  A(Int, Double)
  B(Int)
}

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

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

///|
test {
  f(A(1, 2.0))
  f(B(1))
  use_second(A(1, 2.0))
}