E4217#
Compiler diagnostic name: lexscan_guard_not_supported.
This diagnostic described a guard on a lexmatch or lexscan case and is not
emitted by the current compiler. The parser now rejects this syntax with
E3002.
The scanner selects a case from its regex patterns before it evaluates the case body. A guard would make that selection depend on an arbitrary expression.
Erroneous example#
///|
pub fn classify(input : String, allow : Bool) -> String {
lexmatch input {
re"^[a-z]+$" if allow => "word"
_ => "other"
}
}
Suggestion#
Move the additional condition into the selected case body.
///|
pub fn classify(input : String, allow : Bool) -> String {
lexmatch input {
re"^[a-z]+$" => if allow { "word" } else { "other" }
_ => "other"
}
}