E4186#

Compiler diagnostic name: guard_not_supported_in_longest_match_strategy.

この診断コードは最長一致の字句ケースにおけるガードに使われていましたが、現在のコンパイラでは発生しません。現在の診断は 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#

選択が正規表現パターンだけに依存するよう、条件をケース本体へ移動してください。

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