-
-
Notifications
You must be signed in to change notification settings - Fork 888
fix js codegen allowing underscore after decimal #5125
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
base: main
Are you sure you want to change the base?
Conversation
a3814be to
ed81131
Compare
|
Digging in a bit more, the compiler produces an error ( |
lpil
left a comment
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! Rather than render the float value to a string could you use the original string value please 🙏
...cript/tests/snapshots/gleam_core__javascript__tests__numbers__float_scientific_literals.snap
Outdated
Show resolved
Hide resolved
But using the original string value wouldn't fix the issue this PR is meant to fix. We're already rendering the float value to a string for patterns instead of using the original string value |
Aye, this work is to fix that by changing the output, and the easiest way would be to edit that string.
Does that code have the same bugs as this one does? This PR is generating invalid JavaScript currently. We can use the value here, but we need to ensure that infinity and nan are used in appropriate ways, which requires a bit more work. |
It may have the same issue, I don't think there is an explicit test against the infinity case.
When I get a chance later I'll look deeper into the infinity issue. |
2e899b4 to
b49796f
Compare
|
Looks like the infinity issue also occurs in the case statements after #5118. I created a new function for converting from an Expressions could likely be handled by modifying the original string, but for consistency I think this approach is cleaner (although there was an alternative version of the exhaustiveness checks in #5118 that still output strings in JS codegen). |
Addresses #5124
Fixes invalid generation of JavaScript code in cases where floats contain underscores immediately before/after a decimal point (i.e.
1._23).The changes made here use the parsed value of the float instead of the string representation in generation code. This does result in semantic float formatting in gleam code no longer being preserved in generated JavaScript.
For case statements, this is fixed as a byproduct of the changes made in #5118.
(I'm marking this as a draft until that PR is merged and will add tests for this behavior specifically in a case statement)