E4184

E4184#

Compiler diagnostic name: start_rest_binder_is_not_supported_in_longest_match_strategy.

A leading rest binder is not supported with the longest-match lexmatch strategy.

In lexmatch ... with longest, the engine chooses the longest matching case. Allowing a rest binder before the regex would make that choice ambiguous, so the start rest binder is rejected.

Erroneous example#

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

The first _ attempts to bind or skip input before the "abc" regex pattern.

Suggestion#

Match the regex at the start of the remaining input, and bind only the suffix when needed.

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