# 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

```{literalinclude} /sources/error_codes/4222_error/top.mbt
:language: moonbit
```

## Suggestion

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

```{literalinclude} /sources/error_codes/4222_fixed/top.mbt
:language: moonbit
```
