Skip to content

Conversation

fruno-bulax
Copy link
Contributor

@fruno-bulax fruno-bulax commented Oct 1, 2025

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 a NotNan type to wrap f64 that be NaN and can therefore properly implement Eq and Ord. 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?

Copy link
Member

@giacomocavalieri giacomocavalieri left a 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

Comment on lines +37 to +39
float_value: NotNan(
1.0,
),
Copy link
Member

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?

Suggested change
float_value: NotNan(
1.0,
),
float_value: NotNan::ONE,

Copy link
Contributor Author

@fruno-bulax fruno-bulax Oct 2, 2025

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! 🕵️

Copy link
Member

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 😆

Comment on lines +12 to +13
1pub fn main() { 1_0.0 == 10.0 }
^^^^^^^^^^^^^ This is always `True`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice!!

/// 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.
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect warn on useless comparisons

2 participants