Skip to content

Conversation

mohammadfawaz
Copy link
Collaborator

Original PR: #28897

When users write identifiers starting with underscore, (e.g.: let _c: u32), the parser produces an uninformative error.

Root cause of that is that lexer splits _c into two separate tokens, and the parser had no grammar rule matching the pattern, so LARLPOP generates a generir error listing what tokens it expected at that position (which happened to be '(' for tuple destructuring).

So, this adds new lexer token - InvalidLeadingUnderscoreIdent that catches any leading underscore next to identifiers.

Before:

Error [EPAR0370005]: expected an identifier, '(' -- found '_'
    --> \\?\C:\Users\tetektoza\source\repos\leo\test_underscore_project\test_underscore\src\main.leo:3:13
     |
   3 |         let _c: u32 = a + b;
     |             ^

After:

Error [EPAR0370047]: Identifier cannot start with an underscore
    --> \\?\C:\Users\tetektoza\source\repos\leo\test_underscore_project\test_underscore\src\main.leo:3:13
     |
   3 |         let _c: u32 = a + b;
     |             ^^
     |
     = Identifiers must start with a letter.

Resolves: #28755

When users write identifiers starting with underscore,
(e.g.: let _c: u32), the parser produces an uninformative error.

Root cause of that is that lexer splits `_c` into two separate tokens,
and the parser had no grammar rule matching the pattern, so LARLPOP
generates a generir error listing what tokens it expected at that
position (which happened to be '(' for tuple destructuring).

So, this adds new lexer token - `InvalidLeadingUnderscoreIdent` that
catches any leading underscore next to identifiers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] The parser error provided when an identifier has a leading underscore is very uninformative.

2 participants