-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Match types do not treat 0.0d and -0.0d as equivalent constants #23261
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
Comments
Huh. To me, that is the real bug. |
If it is a value (not a type), the comparison is a match - this appears to be a JVM specification. println(0.0 == -0.0) // => true Since |
Conversely, In general, |
As for 0, since values do not distinguish between positive and negative, I thought it would be better to not distinguish between positive and negative in literal types as well, so that operations could be related to values and types. In fact, positive and negative are not distinguished outside of match types. However, does this mean that it is better to distinguish between (Personally, regardless of the conclusion, I would like the behavior of match types to be the same as others. In other words, if we go with the current situation, I would not like the distinction between positive and negative. If we go with your proposal, I would like the distinction to be made in behavior other than match types, and I would like to be able to put positive and negative zeros in case clauses.) |
Yes, that's what I meant in my first comment. |
… with sign sensitivity - Ensure match types distinguish between 0.0 and -0.0 in pattern matching. - This enables accurate reduction in match types involving Double constants.
- Ensure match types distinguish between 0.0 and -0.0 in pattern matching. - This enables accurate reduction in match types involving Double constants. Close scala#23261
Compiler version
Scala 3.7.0
(Confirmed with both sbt and Scala CLI)
Minimized code
Compilation output
Problem description
In Scala 3.7.0, match types cannot distinguish or unify
0.0
and-0.0
, even though:0.0d == -0.0d
holds at runtime=:=
on the type level compiles successfully:summon[0.0 =:= -0.0]
worksHowever, in match types, writing
case 0.0 =>
causes-0.0
to be rejected as an uninhabited selector.Switching to
case -0.0 =>
then rejects0.0
.This suggests that match types are not treating
0.0d
and-0.0d
as equivalent constant values, which is inconsistent with how=:=
treats them.Expected behavior
Match types on
Double
constants should not distinguish0.0
and-0.0
, just as=:=
does not.The text was updated successfully, but these errors were encountered: