fix: #23261 Distinguish 0.0 and -0.0 in ConstantType match types#23265
fix: #23261 Distinguish 0.0 and -0.0 in ConstantType match types#23265sjrd merged 1 commit intoscala:mainfrom
Conversation
| compareErasedValueType | ||
| case ConstantType(v2) => | ||
| tp1 match { | ||
| case ConstantType(v1) => v1.value == v2.value && recur(v1.tpe, v2.tpe) |
There was a problem hiding this comment.
MEMO
I tried to modify the Constants.scala below to change the processing of the == method, but it didn't work.
There was a problem hiding this comment.
The line should use equals, which is already correct, see equalHashValue comment.
case ConstantType(v1) => v1.value.equals(v2.value) && recur(v1.tpe, v2.tpe)
There was a problem hiding this comment.
sorry, second look says
v1 == v2 && recur(v1.tpe, v2.tpe)
Do not unwrap Constant to underlying value, use equals on Constant.
There was a problem hiding this comment.
The internal tag in Constant is already checked for equality. Then recur(v1.tpe, v2.tpe) is not needed.
However, what about ClazzTag where Constant wraps a Type?
In general, the equals check is wrong. But if the underlying type is always some normalized class type, and it's comparing invariant Class[C], then the existing v1.value == v2.value is correct (and v1 == v2 is also correct).
| @@ -0,0 +1,7 @@ | |||
| @main def main(): Unit = | |||
| summon[0.0 =:= -0.0] | |||
There was a problem hiding this comment.
summon[0.0 =:= -0.0] // error
to annotate an expected error on that line
- 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
som-snytt
left a comment
There was a problem hiding this comment.
I suspect the call to recur is extraneous and could be deleted, but it must also be correct to leave it as it is. (It is no less correct than the existing code.)
| compareErasedValueType | ||
| case ConstantType(v2) => | ||
| tp1 match { | ||
| case ConstantType(v1) => v1.value == v2.value && recur(v1.tpe, v2.tpe) |
There was a problem hiding this comment.
The internal tag in Constant is already checked for equality. Then recur(v1.tpe, v2.tpe) is not needed.
However, what about ClazzTag where Constant wraps a Type?
In general, the equals check is wrong. But if the underlying type is always some normalized class type, and it's comparing invariant Class[C], then the existing v1.value == v2.value is correct (and v1 == v2 is also correct).
Fixes #23261