-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Lint for integral divisions that are widened to a float #10313
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c11c480
to
df1b859
Compare
SethTisue
reviewed
Feb 20, 2023
SethTisue
reviewed
Feb 20, 2023
SethTisue
reviewed
Feb 20, 2023
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.
LGTM except for the minor tweaks I've suggested
som-snytt
reviewed
Feb 20, 2023
I tested this, it works well and seems very valueable. |
I'm going to try this out! I hope the change is not too divisive. |
hamzaremmal
pushed a commit
to hamzaremmal/scala3
that referenced
this pull request
May 2, 2025
hamzaremmal
pushed a commit
to scala/scala3
that referenced
this pull request
May 7, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add a lint warning for integer divisions that are implicitly converted to floats (
someInt / 2: Double
). Such expressions are probably a mistake, or otherwise very likely to be misunderstood by reviewers / readers.The same argument could be made for other integer operations as they can overflow.
Int.MaxValue * 2: Double
is different fromInt.MaxValue.toDouble * 2
. But division is much more likely to be a bug because the result is different also without an overflow.The existing
-Ywarn-numeric-widen
flag (-Wnumeric-widen
on 2.13) warns about all widening conversions, which is probably too restrictive for some users.While working on this, I noticed a couple of extension methods on integrals that are nonsensical:
ceil
,floor
,isNaN
,isNegInfinity
,isPosInfinity
,isInfinite
,isInfinity
,isFinite
. We could add a warning for those in RefChecks, for example.someInt.isNaN
compiles toPredef.float2Float(someInt.toFloat).isNaN
, the widening conversiontoFloat
is inserted during implicit search.