E4186

E4186#

Compiler diagnostic name: guard_not_supported_in_longest_match_strategy.

Guards are not supported in longest-match lexmatch cases.

The longest-match strategy decides which regex case wins before running the case body. Case guards would make that decision depend on arbitrary expressions, so they are rejected for lexmatch ... with longest.

Erroneous example#

///|
pub fn match_text(text : String) -> Unit {
  lexmatch text with longest {
    "abc" if text.length() > 0 => ()
    _ => ()
  }
}

The first case has an if guard.

Suggestion#

Move the condition into the case body so the longest-match decision depends only on the regex patterns.

///|
pub fn match_text(text : String) -> Unit {
  lexmatch text with longest {
    "abc" => if text.length() > 0 { () }
    _ => ()
  }
}