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
Incorrect output in toHexString applied to Byte and Short values #10216
Comments
Imported From: https://issues.scala-lang.org/browse/SI-10216?orig=1 |
@som-snytt said: scala> 42.toHexString //print
scala.Predef.intWrapper(42).toHexString // : String
scala> -1.toByte.toHexString //print
scala.Predef.intWrapper(-1.toByte.toInt).toHexString // : String
There is no scala> f"${-1.toByte}%x"
res0: String = ff I'm not sure there is a welcome tag for the label field like they have on github. |
Nilay Pochhi (npochhi) said (edited on Mar 8, 2017 7:34:08 PM UTC): |
@SethTisue said: |
@SethTisue I'm confused after going through the discussions, is it concluded that the toHexString function would be deprecated?? |
I'm not convinced deprecation is a better solution than making it work properly for every numeric type, like we do with min and max and so on. |
@Ichoran it makes sense not to deprecate it rather find a proper solution for it |
|
All the moles need to be whacked. There aren't that many of them. You don't need to pave everything over with concrete to solve the problem. |
What is the conclusion? Deprecating toHexString or creating the richness for the other types? |
In every generation, one is chosen to whack the moles. Endowed with extraordinary skill and patience, a whacker will rise after some years to find the moles and then whack them, and the moles will fall. |
lol i just want a first issue to work on haha |
Then just maybe, you are the chosen one. Only by whacking the moles we can
be sure.
…On Tue, May 28, 2019, 16:27 Jacob Niebloom ***@***.***> wrote:
lol i just want a first issue to work on haha
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#10216?email_source=notifications&email_token=AAGXOEPEWIOUDXKHRGZRWALPXU6N3A5CNFSM4DXJGLMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWMJXBQ#issuecomment-496540550>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGXOEMRC2PPDE5BAYMTALLPXU6N3ANCNFSM4DXJGLMA>
.
|
Can someone assign this to me so that there isn't duplicated work? Thank you. The moles will be whacked. |
Please consider this ticket assigned to you. GitHub only allows assigning to organisation members, but if someone else looks at this ticket they will see your comment. |
So if I understand this correctly, numeric types get implicitly converted to their respective respective For
For converting short to hex, I'm not sure how to go about implementing it for the PR. I don't understand why the second style works though. Is something like this okay, or should there be guarantee that what comes in to the method is a
|
@nogurenn both of those implementations look pretty reasonable. I believe there is a |
@NthPortal Wait, it just hit me. Does this imply we also need to work out stuff for |
scala> -1.toBinaryString
res0: String = 11111111111111111111111111111111
scala> -1.toByte.toBinaryString
res1: String = 11111111111111111111111111111111 @nogurenn yes |
Sorry I missed the updated conversation. I gave this a nudge. Maybe the test could be further improved as an exercise? Normally you would expect a junit test, but I left it as partest because of possible issues around widening or implicit selection, it's better to test the compiler being built. @nogurenn the rules for the numeric ops are https://scala-lang.org/files/archive/spec/2.13/12-the-scala-standard-library.html#numeric-value-types where it says the short gets promoted to int first. The constant arg in |
Forgot to add that the fix is not binary compatible. Luckily 2.14 milestone is due by end of the year. Edit: famous last words. |
Not only is this out of scope for Scala 2, the PR was never merged at |
This is my very first issue submission to Scala, so I apologize in advance for any mistakes I might have made in filling out the different fields.
Calling
toHexString
method on numeric types other than Int will produce unexpected output. I believe thattoHexString
is not implemented inByte
andShort
and an implicit conversion toInt
is happening.The text was updated successfully, but these errors were encountered: