E4171#
Compiler diagnostic name: last_regex_case_must_be_catchall.
lexmatch 或 lexscan 表达式中的兜底分支必须是最后一个分支。
一旦到达兜底分支,后续正则分支就永远不会被选中。
错误示例#
///|
pub fn match_text(text : String) -> Unit {
lexmatch text with longest {
_ => ()
re"^abc$" => ()
}
}
_ 分支出现在另一个正则分支之前。
修改建议#
将兜底分支移到最后。如果表达式完全没有兜底分支,请参阅 E4224。
///|
pub fn match_text(text : String) -> Unit {
lexmatch text with longest {
re"^abc$" => ()
_ => ()
}
}