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 free variable when the pattern is matched, which is not allowed.

错误示例:#

enum E {
  A(Int, Double)
  B(Int)
}

fn f(value : E) -> Unit {
  match value {
    A(a, _) | B(_) => println("Hello") // Error: Variable a is not bound in all patterns.
  }
}

建议#

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