-
-
Notifications
You must be signed in to change notification settings - Fork 875
✨Use parsed float value for useless comparison warnings #5030
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
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.
This is great, well done!! I left just a tiny nit inline
float_value: NotNan( | ||
1.0, | ||
), |
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.
Isn't this the ONE
constant you defined earlier?
float_value: NotNan( | |
1.0, | |
), | |
float_value: NotNan::ONE, |
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.
This is the snapshot of the parser test, not rust code! 🕵️
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.
Oh my, sorry for that, I totally missed the context 😆
1 │ pub fn main() { 1_0.0 == 10.0 } | ||
│ ^^^^^^^^^^^^^ This is always `True` |
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.
Really nice!!
compiler-core/src/parse.rs
Outdated
/// A thin f64 wrapper that does not permit NaN. | ||
/// This allows us to implement `Eq`, which require reflexivity. | ||
/// | ||
/// Used for gleam float literals. May contain infinity. |
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.
If this is used for Gleam float literals it shouldn't contain infinity as well, should it?
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.
This is true for the Erlang target (and there is a compile time check for it), but on JS you can enter float literals that are too large (e.g. 1.0e500
) and they turn into (negative) infinity.
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.
Aha, now I see, thanks for explaining! Would you mind adding this explanation to the comment? That would be really helpful for future people wondering the same thing
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.
Good point, done!
9ca2823
to
6fa1918
Compare
6fa1918
to
573bd5d
Compare
Closes #5001
Parallel to the implementation for ints, we're now parsing the literal value and passing it along the AST.
This allows us to do smarter useless comparison warnings instead of relying on string comparison.
To maintain the
Eq
trait impl on many types, I created aNotNan
type to wrap f64 that beNaN
and can therefore properly implementEq
andOrd
. I wasn't quite sure where to put the type, I'll gladly move it.I noticed that we still do string-based checks in case expressions for both ints and floats, I'll create a follow-up issue after this is merged.
I'm not sure how you'd like the changelog updated when there's an RC out. Do I just add a new
Unreleased
header at the top?