Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Diagnostic given sometimes when naming type #2998

Open
u9g opened this issue Apr 17, 2024 · 5 comments
Open

Incorrect Diagnostic given sometimes when naming type #2998

u9g opened this issue Apr 17, 2024 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Contributions encouraged priority:medium

Comments

@u9g
Copy link

u9g commented Apr 17, 2024

As seen in the screenshot, the compiler gives the diagnostic that "names" should start with lowercase letters despite this being a type name, which should give the second diagnostic shown.

image

image

@lpil lpil transferred this issue from gleam-lang/language-tour Apr 17, 2024
@lpil
Copy link
Member

lpil commented Apr 18, 2024

Oops. Thank you!

@lpil lpil added bug Something isn't working help wanted Contributions encouraged good first issue Good for newcomers priority:high labels Apr 18, 2024
@Acepie
Copy link
Contributor

Acepie commented Apr 19, 2024

Looks like the difference between the two is that the first one errors earlier as a lexer error before even getting to the parser for the compiler to figure out if it expected a value name or a type name. We could either change the error message to be applicable to either or we could somehow switch the lexer to accept this and move the error forward to the parser.

FWIW you can also get the opposite error (expected a value name but user started with an uppercase and gets a lex error) for the same reason as shown in the screenshot below.

Screenshot 2024-04-18 at 6 22 40 PM

Changing the error message is definitely the easier/less error prone option since I think the alternative would probably require lexing both as a single token type and disambiguating in the parser but not sure if the user experience would actually be better (i.e would we be better off just having a single bad name message that mentions both the type and value constraints)

@Acepie
Copy link
Contributor

Acepie commented Apr 19, 2024

Alternatively instead of immediately returning a lex error for these cases we make a new token type for a generic bad name and continue lexing so that the parser can decide which one it wanted

Edit: looking at this more in the code there are a lot of places where it actually is ambiguous since constructor variants are valid value UpNames so this would probably just shift the confusion forward/to more places

@lpil
Copy link
Member

lpil commented Apr 19, 2024

We're talking about relaxing the parsing of lowercase names and turning them into an error in analysis in order to enable the formatter to auto-correct function names. That would enable us to give error messages with more context here too if we decide to do that.

#2978

@Arian94
Copy link

Arian94 commented May 24, 2024

The thing I can think of is that in this language the naming convention is determined by its previous token (let, type etc.) so THIS should be the controlling factor in the consume_normal() implementation but one can see that the name itself is being examined in order to give proper corrections. That's the real issue and a refactor might be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Contributions encouraged priority:medium
Projects
None yet
Development

No branches or pull requests

4 participants