E4217

E4217#

Compiler diagnostic name: lexscan_guard_not_supported.

此诊断用于描述 lexmatchlexscan 分支带有守卫的情况,当前编译器已不再产生该诊断。解析器现在会以 E3002 拒绝此语法。

扫描器会先根据正则模式选择 case,再执行 case 函数体。守卫会使这个选择依赖任意表达式。

错误示例#

///|
pub fn classify(input : String, allow : Bool) -> String {
  lexmatch input {
    re"^[a-z]+$" if allow => "word"
    _ => "other"
  }
}

建议#

将额外条件移入被选中的 case 函数体。

///|
pub fn classify(input : String, allow : Bool) -> String {
  lexmatch input {
    re"^[a-z]+$" => if allow { "word" } else { "other" }
    _ => "other"
  }
}