E4222

E4222#

Compiler diagnostic name: invalid_lexscan_target.

Invalid lexical matching target.

lexmatch accepts an in-memory String or StringView. lexscan is intended for @lexbuf.Lexbuf or @lexbuf.AsyncLexbuf. It temporarily also accepts String and StringView for compatibility, but emits a deprecation warning; use lexmatch for those inputs. Other values, such as numbers or user-defined lexbuf-like types, cannot be matched by these expressions.

Erroneous example#

///|
pub fn match_number(number : Int) -> Unit {
  lexmatch number with longest {
    _ => ()
  }
}

Suggestion#

Use lexmatch with a string-like value, or create a lexing buffer for lexscan.

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