-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
ClassCastException during pattern matching #2401
Comments
Luckily the Match generics are correct. The pattern matcher The error is located in the implementation of It uses the internal Which does a check by contents. Therefore Match matches (because Pattern0.isDefinedAt returns equals == true), then the case is performed, then -----> 💥 I will fix that and check all other locations which could be affected by Collections.equals! Many thanks! 😊 |
A fix could look like this: static <V> boolean equals(Seq<V> source, Object object) {
if (object == source) {
return true;
- } else if (source != null && object instanceof Seq) {
+ } else if (source != null && object != null && source.getClass() == object.getClass()) {
final Seq<V> seq = (Seq<V>) object;
return seq.size() == source.size() && areEqual(source, seq);
} else {
return false;
}
} Other |
Looks like changing the Collections.equals() implementatios has a bigger impact on the code-base than I thought 😅. I will get it right! |
@danieldietrich I’m really impressed how fast you react on this issue. Thanks for the good work on vavr. |
Our notion of collection equality is aligned to that of Scala. All collections that share the same parent type (Seq / Set / Map) are equal (by definition), if they contain the same elements (modulo order). However, I'm aware of the fact that might be unexpected to Java developers. Changing But fixing pattern matching is a must. In order to fix this bug, I will change the implementation of Pattern0 the way, that |
I think your / vavrs / scalas notion of collection equality is right. |
@danieldietrich Wow. Thanks for the fast fix! |
I'm not sure if the result of this fix was intended. The following documents the difference between "match" and "equality check":
I'm aware of the fact that this is not a breaking change due to the raised |
Thanks for your work, Daniel! This bug (I think) is blocking me in 0.10.0 because it causes |
@chrylis I will release a backward compatible 1.0 within this or the next week. |
Thx @goerge for reporting this bug on Gitter!
The text was updated successfully, but these errors were encountered: