E4217

E4217#

Compiler diagnostic name: lexscan_guard_not_supported.

lexscan cases do not support guard conditions.

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 {
  lexscan 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 {
  lexscan input {
    re"^[a-z]+$" => if allow { "word" } else { "other" }
    _ => "other"
  }
}