-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add helpful error message for invalid number literal like '.42' #4665
Add helpful error message for invalid number literal like '.42' #4665
Conversation
I'd suggest a wording like |
Or just follow the octal literal message (
|
float literals should be started with decimal digit |
@ysbaddaden I think the wording should differentiate between constant and literal. So we should probably change the octal message to literal as well. Plus, prefixing float literals with 0 in general would actually be wrong (like What about:
|
What happens if you write |
Why Crystal not supporting |
@david50407 |
@asterite |
@makenowjust It's hard. I don't know if we should give an error. I wouldn't expect this:
to give an error:
(this is not C, it's Crystal) I mean, we can't give an error for every idiom or piece of syntax that appears in other languages. If you get an error in |
@asterite Nevertheless I believe such an error message is helpful and useful. For example $ ruby -e .42
-e:1: no .<digit> floating literal anymore; put 0 before dot
-e:1: syntax error, unexpected '.' |
There is a difference between those cases: writing |
@makenowjust oops I missed that possible How about just give a nicer tip like:
|
@david50407 $ echo 'def foo bar; end' > foo.cr
$ crystal run foo.cr
Syntax error in foo.cr:1: unexpected token: bar (parentheses are mandatory for def arguments)
def foo bar; end
^
I'll try to implement by using it. |
Even though it's a small thing, I believe this kind of small things makes a language more friendly to newcomers 👍 |
I'd like to see this merged. It's not a strict necessity, but as @sdogruyol puts it, a small think to make the language more friendly to its users (in this case newcomers specifically). My preferred error message: |
@makenowjust can you rebase this? Let us know otherwise. Thanks! |
… '.42' Dot-started floating-point number like '.42' is not supported on Crystal. However compiler does not tell us this, so this fix adds to detect such a literal and to show helpful error message.
7033c37
to
a6283d4
Compare
|
Dot-started floating-point number like '.42' is not supported on Crystal. However compiler does not tell us this, so this fix adds to detect such a literal and to show helpful error message.
For example, old compiler shows an error message:
And this PR compiler shows:
If you have more helpful error message text, please tell me. You know, my English is not good.