Comments (2)
> JE.object [ ("a", JE.list identity []) ] == JE.object []
True : Bool
> JE.object [ ("a", JE.object []) ] == JE.object []
True : Bool
These two happen because we (after some recursion into the objects) call __Utils_eq([], undefined, depth, stack)
. We do not enter the if here https://github.com/elm/core/blob/65cea00afa0de03d7dda0487d964a305fc3d58e3/src/Elm/Kernel/Utils.js#L34 because x is an object (y isn't). Then we look at all the properties of []
and there are not any so we say the two objects are equal.
The fix is to check if y is an object in https://github.com/elm/core/blob/65cea00afa0de03d7dda0487d964a305fc3d58e3/src/Elm/Kernel/Utils.js#L34.
> JE.object [ ("a", JE.null) ] == JE.object [ ( "a", JE.null ), ( "b", JE.null ) ]
True : Bool
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 Object.keys
polyfill probably).
[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.
from json.
There is one more case
> JE.object [ ] == JE.list identity []
True : Bool
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 Array.isArray(x) == Array.isArray(y)
(polyfilled).
All of this does seem wasteful; we would pay a cost for every (not special cased by compiler) equality in elm to make Json.Encode.Value
equality work. I suspect no one much uses Json.Encode.Value
equality anyway although I have no data to back that theory up.
from json.
Related Issues (20)
- Decode.andMap? HOT 2
- elm/files is broken in IE
- Invalid list equality check.
- Chooses a more positive example
- Json equality for oneOf decoders always returns true HOT 2
- Detect attempts to install packages for an older version of elm
- Encode.dict & Decode.dict are asymmetrical HOT 1
- Json.Decode.index checks for too large index but not too small
- Is there a way to decode "jsonlines" format with this library? HOT 2
- Runtime exception when using Decode.dict on a JSON created with Object.create(null)
- Add a function to create a Decoder from an Error value HOT 1
- Decoder error even-though it's correct
- Doesn't compile if a decoder for a recursive structure is not defined at top level
- Using `==` on `Json.Decode.Value`s can throw runtime exceptions HOT 1
- Json.Json! HOT 1
- Encoding an object with circular dependencies throws an Error.
- elm-decode-pipeline link is wrong
- Decoding an object with an absent field HOT 1
- Regression in 1.1.0 - Decode.dict fails for trivial input HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json.