E4022#

Compiler diagnostic name: unbound_constant.

Unbound regex constant.

正規表現マッチ式、および lexmatchlexscan のケースでは、正規表現定数を参照できます。その定数は宣言済みで、使用箇所から参照可能でなければなりません。名前を定数として解決できない場合、MoonBit はこのエラーを報告します。

Erroneous example#

The following example refers to WORD without declaring it:

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

///|
test {
  ignore(has_word)
}

MoonBit will report an error.

Suggestion#

Declare the regex constant before using it, or use a regex literal directly:

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

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

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