E4186

E4186#

Compiler diagnostic name: guard_not_supported_in_longest_match_strategy.

This diagnostic code was used for guards in longest-match lexical cases and is not emitted by the current compiler. The current diagnostic is E4217.

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 selection depends only on the regex patterns.

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