leo/docs/error-guides/parser/unexpected.md
2022-02-28 09:42:37 -08:00

830 B

Expected "x" -- got "y"

Example

This error occurs when a specific token, e.g., class was encountered but a different one, e.g., circuit was expected instead.

Erroneous code example:

class A {}

The compiler will reject this code with:

Error:     --> main.leo:1:1
     |
   1 | class A {}
     | ^^^^^
     |
     = expected 'import', 'circuit', 'function', 'test', '@' -- got 'class'

Solutions

The error message above says that class cannot be used at that location, and also lists a few tokens that are valid. Note that this is context specific, and depends on what tokens preceded the current token. Using the list of tokens that are valid, and knowing that circuit A {} is valid syntax, we replace class with circuit...:

circuit A {}

...and the error is now resolved.