E4022

E4022#

Compiler diagnostic name: unbound_constant.

未绑定的正则常量。

正则匹配表达式和旧的 lexmatch 模式可以引用正则常量。该常量必须已经声明,并且在使用位置可见。如果名称无法解析为常量,MoonBit 会报告此错误。

错误示例#

下面的示例在未声明 WORD 的情况下引用了它:

///|
fn has_word(input : String) -> Bool {
  input =~ WORD
}

///|
test {
  ignore(has_word)
}

MoonBit 会报告一个错误。

建议#

先声明正则常量再使用,或者直接使用正则字面量:

///|
const WORD = re"[A-Za-z]+"

///|
fn has_word(input : String) -> Bool {
  input =~ WORD
}

///|
test {
  inspect(has_word("MoonBit"), content="true")
}