E4184

E4184#

Compiler diagnostic name: start_rest_binder_is_not_supported_in_longest_match_strategy.

此诊断描述的是早期词法模式语法中的前置剩余部分绑定,当前编译器不会发出该诊断。当前对应的绑定错误是 E4220

lexmatch ... with longest 中,每个正则都从输入开头开始,因此不能使用 before=

错误示例#

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

第一个 _ 试图在 "abc" 正则模式之前绑定或跳过输入。

修改建议#

请使用以 ^ 锚定的正则,并仅在需要时通过 after= 绑定后缀。

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