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

Deprecate numeric widening of numeric literals which are not representable with Float/Double #8757

Conversation

fabianpage
Copy link
Contributor

@fabianpage fabianpage commented Feb 26, 2020

follow up for: #8679
fixes scala/bug#10773

@scala-jenkins scala-jenkins added this to the 2.13.3 milestone Feb 26, 2020
@fabianpage
Copy link
Contributor Author

I forgot to do the same check for Doubles, working on that now.

@fabianpage fabianpage changed the title Deprecate numeric widening of Long Literals bigger than 2^24 to Float Deprecate numeric widening of Numeric Literals which are not representable with Float/Double Feb 26, 2020
@fabianpage fabianpage force-pushed the deprecate_numeric_widening_of_too_big_long_literals_to_float branch from c8cb24b to e88a7cb Compare February 26, 2020 13:16
@som-snytt
Copy link
Contributor

How does it compare to #8730 ?

@fabianpage
Copy link
Contributor Author

@som-snytt i don't have enough knowledge of the compiler to answer that question. I could add your tests to my solution to check if they also warn.

@lrytz
Copy link
Member

lrytz commented Feb 27, 2020

(context: https://twitter.com/darjutak/status/1232599151537512448, we're on the left in the first photo. i missed / didn't remember your PR, @som-snytt)

@som-snytt
Copy link
Contributor

Thanks, I see. Previously, I was only reading tpolecat on twitter, but now I will also read darjutak. I may even read darjutak first. Maybe we could use a spree tag here.

The "roundtrip" test in the other PR, borrowed from doti, is more generous.

@fabianpage
Copy link
Contributor Author

But with the roundtrip you will have Integer values which are okay, but the value one bigger or one smaller would not be okay. In my opinion it's nicer to war a soon as you start to truncate.

@som-snytt
Copy link
Contributor

Yes, I don't have a strong opinion about the ergonomics. I was trying to "align with doti" a bit, but dotty has sharp edges, such as Array(3.14f, 0x_7FFF_FFFE) infers Float unlike Seq[AnyVal].

The use case is if I can get my integral value out again, for example it's a sentinel, then there is no reason to warn. If I am computing with it, the opinion on the other ticket was not to warn about operations; I asked why is 3.14f + 1 different from any other f(1: Float)?

What is the use case for warning about conversion to a float that is never used in a computation? I computed an int, but my spreadsheet report generator only takes a float?

The doti use case is just about the type inference.

@lrytz lrytz modified the milestones: 2.13.3, 2.13.2 Feb 28, 2020
@lrytz lrytz mentioned this pull request Mar 3, 2020
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Mar 4, 2020
@SethTisue SethTisue changed the title Deprecate numeric widening of Numeric Literals which are not representable with Float/Double Deprecate numeric widening of numeric literals which are not representable with Float/Double Mar 4, 2020
@lrytz lrytz merged commit 4aad5dc into scala:2.13.x Mar 4, 2020
@fabianpage
Copy link
Contributor Author

@lrytz @som-snytt thanks for your work!

@lrytz
Copy link
Member

lrytz commented Mar 4, 2020

Thanks for your contribution and the friendly pair-coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
5 participants