-
Notifications
You must be signed in to change notification settings - Fork 25
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
Using == on Json.Decode.Values can return True
for values that aren’t equal
#30
Comments
These two happen because we (after some recursion into the objects) call The fix is to check if y is an object in https://github.com/elm/core/blob/65cea00afa0de03d7dda0487d964a305fc3d58e3/src/Elm/Kernel/Utils.js#L34.
This one happens because we ignore any properties of the right hand side that are not also properties of the left hand side [1]. The fix is to compare the number of properties of x and y (using an [1]The code was probably written only thinking about elm records where the compiler ensures the properties of the left and right hand sides are the same or elm custom types where either the properties are the same or the value '$' of will be different. |
There is one more case
Maybe it is okay to say these two are equal? After all they have all the same properties (!) Otherwise we would need a defensive check All of this does seem wasteful; we would pay a cost for every (not special cased by compiler) equality in elm to make |
SSCCE
Edit: This Discourse post by Evan explains that
(==)
shouldn’t be used with JSON values from elm/json and an idea for improving this in the future: https://discourse.elm-lang.org/t/function-equality/7538/24Edit2: It’s even documented that one shouldn’t use
(==)
with JSON values: https://package.elm-lang.org/packages/elm/core/latest/Basics#equality 😅 But who reads the docs for(==)
, right?The text was updated successfully, but these errors were encountered: