E4171#
Compiler diagnostic name: last_regex_case_must_be_catchall.
The last case in a lexmatch expression must be a catch-all pattern.
MoonBit checks lexmatch expressions for exhaustiveness. When all previous
regex patterns fail, the expression still needs a final branch that can handle
the remaining input.
Erroneous example#
///|
pub fn match_text(text : String) -> Unit {
lexmatch text with longest {
"abc" => ()
}
}
The only branch matches "abc", so other input has no branch to run.
Suggestion#
Add a final _ case, or otherwise make the last case catch all remaining input.
///|
pub fn match_text(text : String) -> Unit {
lexmatch text with longest {
"abc" => ()
_ => ()
}
}