-
-
Notifications
You must be signed in to change notification settings - Fork 669
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
Better error message for triple equals #3150
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Could you add a test to ensure that this code does not result in that helpful error:
== =
I think currently it will show the error in this case, which isn't what we want.
It may be better to implement this in the tokeniser rather than in the parser.
d9965be
to
370ab3c
Compare
Thank you for the recommendation, I made the changes and now the logic is handled in tokenizer, let me know if the error message is good enough, if it is not we can add a special case like these
|
Hello! I gave this a try and I got this error:
This doesn't seem any clearer to me than the previous error. Let's have one like Giacomo suggested in the issue, that'll help the programmer understand what the problem is. I also tested with |
370ab3c
to
7aec081
Compare
Thank you for the suggestions, made changes as requested please check 👍🏽 |
compiler-core/src/parse/error.rs
Outdated
LexicalErrorType::InvalidOperator { expected } if *expected == "==" => ( | ||
"Did you mean `==`?", | ||
vec![ | ||
"Gleam uses `==` to check for equality between two values.".into(), | ||
"See: https://tour.gleam.run/basics/equality".into(), | ||
], | ||
), | ||
LexicalErrorType::InvalidOperator { expected } => ( | ||
"This is not a valid operator at this context", | ||
vec![ | ||
"Hint: Is it a typo?".into(), | ||
format!("Try: `{}` operator instead.", expected), | ||
], | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd personally define a specific InvalidTripleEqual
error variant instead of a general InvalidOperator
one since we don't currently have any uses for it besides the triple equal case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review updated the commit 👍🏽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, thank you!
7aec081
to
b74935a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Very nice. Could you update the changelog file too?
cb9311e
to
40620a5
Compare
40620a5
to
6bec302
Compare
Thank you, added the changelog 👍🏽 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful! Thank you
fix: #3125
This is the new error message after the fix: