E4022#
Compiler diagnostic name: unbound_constant.
Unbound regex constant.
Regex match expressions and legacy lexmatch patterns can refer to regex
constants. The constant must be declared and visible at the use site. If the
name cannot be resolved as a constant, MoonBit reports this error.
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")
}