E1010

E1010#

This pattern is unused. This usually happens in pattern matching, and this pattern is completely covered by a prior pattern.

Pattern matching in MoonBit is executed sequentially, from the first branch to the last. If a pattern is covered by a prior pattern, it will never be reached, since all control flow will be directed to the first matching branch.

Erroneous example#

fn main {
  match Some(1) {
    _ => println("_")
    Some(a) => println("Some(\{a})") // Warning: Unused pattern
  }
}

Suggestion#

This warning can be usually fixed by swapping the order of the branches in the pattern matching. If the order of the branches is important, then you may want to refine the first pattern so that it excludes what the second pattern covers.

fn main {
  match Some(1) {
    Some(a) => println("Some(\{a})")
    _ => println("_")
  }
}

Or,

fn main {
  match Some(1) {
    None => println("_")
    Some(a) => println("Some(\{a})")
  }
}