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

structural and shallow comparers have false positives for different collection types #2239

Closed
hearnden opened this issue Dec 17, 2019 · 5 comments
Labels

Comments

@hearnden
Copy link
Contributor

hearnden commented Dec 17, 2019

A comparison of different collection types should presumably always fail. For example, both of these comparisons should presumably fail:

   comparer.structural(new Set([1, 2]), [[1, 1], [2, 2]])
   comparer.shallow(new Set(), [])

However, both pass.

eq unwraps ES6 collection types to Arrays before the same-type test, which produces those false equalities:

mobx/src/utils/eq.ts

Lines 30 to 33 in 3fe3ada

// Unwrap any wrapped objects.
a = unwrap(a)
b = unwrap(b)
// Compare `[[Class]]` names.

This can presumably be fixed by moving the unwrapping to after the same-type test.

@urugator
Copy link
Collaborator

urugator commented Dec 17, 2019

It seems intentional, but I don't think it's useful - I can't imagine computed/reaction altering between produced types, unless the types actually represent different value.

What also seems troubling is treating Set as ordered collection...

EDIT: ...and the same goes for Map I suppose ... as you've already pointed out #2237

@mweststrate

@mweststrate
Copy link
Member

I think the set case is just an oversight, as they have been bolted on later. PRs to fix welcome!

cc @auvipy this is a nicely limited scoped PR if you want to get hands on :)

@hearnden
Copy link
Contributor Author

PRs to fix welcome!

Sure thing, I raised a PR here (I should have mentioned it in the description):
#2240

@mweststrate
Copy link
Member

Fixed in (4/5).15.2.

@lock
Copy link

lock bot commented Mar 17, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants