Skip to content
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

Warn constant promotions #8730

Closed
wants to merge 3 commits into from
Closed

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Feb 19, 2020

Warn if widening of literal Int or Long is not safe,
which is defined as the conversion roundtrips, the
test used for harmonization.

Fixes scala/bug#10773

Warn if widening of literal Int or Long is not safe,
which is defined as the conversion roundtrips, the
test used for harmonization.

The test means that if I want to convert precisely back to my
original value, I can do so. It does not mean the converted
value maintains accuracy or number of significant digits.

An attachment is used to defer the warning, since typechecking
may consider expressions which are discarded, such as
conversions during implicit search.
@lrytz
Copy link
Member

lrytz commented Mar 3, 2020

After comparing this PR with #8757, I have a tendency for the simpler solution over there. This PR introduces a warning when calling def +(x: Int): Float, but only if the receiver is a literal, which seems a bit ad-hoc to me.

Whether to do the roundtrip or based on the number of bits, I'm fine with both.

The commit message mentions to avoid warnings during implicit search, can you give an example? I wonder if this affects the other PR.

@som-snytt
Copy link
Contributor Author

@lrytz the issue on the original PR #7405 (comment) was whether the warning could be an ordinary deprecation, but n max 42 in the test would trigger it. The use an attachment to trigger the warning on the tree that survives typer is the workaround. I have no opinion on whether to warn on binary op of literals, who does that anyway?

@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Mar 4, 2020
@lrytz
Copy link
Member

lrytz commented Mar 4, 2020

OK thanks, I remember the deprecation issue now. Maybe extending ContextReporter to buffer deprecations is more uniform with what we already have?

I integrated the changes from this PR into #8757.

@lrytz lrytz closed this Mar 4, 2020
@SethTisue SethTisue removed the release-notes worth highlighting in next release notes label Mar 4, 2020
@SethTisue SethTisue removed this from the 2.13.2 milestone Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants