E4224#
Compiler diagnostic name: lexscan_catchall_missing.
The regex cases in a lexmatch or lexscan expression are not exhaustive, and
the expression has no catch-all case.
The compiler checks whether the regex cases cover every possible input, including empty input and, for streaming scans, end of input. An exhaustive expression may omit the catch-all. Otherwise, add a final catch-all branch to define the result when no regex case matches.
Erroneous example#
///|
pub fn classify(text : String) -> String {
lexmatch text with longest {
re"^[a-z]+$" => "word"
}
}
Suggestion#
Make the regex cases exhaustive, or add a final catch-all case. A lexmatch
catch-all may bind the unmatched input; a lexscan catch-all must be written
as _, including when its target is a StringScanner. If a catch-all exists
but is not last, see E4171.
///|
pub fn classify(text : String) -> String {
lexmatch text with longest {
re"^.*$" => "text"
}
}