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

== raises an exception when Json.Encode.Values are not equal below the first level #1058

Closed
BrianHicks opened this issue Oct 24, 2019 · 3 comments

Comments

@BrianHicks
Copy link

As in #1057, I expect this also happens on Json.Decode.Values—I can demonstrate it in my production code but Json.Encode.Value was simpler to make into an SSCCE.

Code on Ellie (reproduced below):

module Main exposing (main)

import Html exposing (text)
import Json.Encode exposing (Value, null, object)


value1 : Value
value1 =
    object [ ( "field", null ) ]


wrap : Value -> Value
wrap wrapped =
    object [ ( "wrapper", wrapped ) ]


main =
    Html.text (Debug.toString (wrap value1 == value1))

I expected this to print "False" but it crashed instead.

It appears that _Utils_eqHelp checks if either value is null but not if they are undefined. Then it tries to access a value like undefined[field], which raises an exception.

@avh4
Copy link
Member

avh4 commented Oct 24, 2019

I expect this also happens on Json.Decode.Values

FYI, Json.Decode.Value is simply a type alias to Json.Encode.Value

@BrianHicks
Copy link
Author

Yep, I know! That's why I expect it will happen on either, but I just wanted to be up front about which I tested with 😄

@evancz
Copy link
Member

evancz commented Oct 24, 2019

Equality is not supported for Json.Encode.Values for a variety of reasons. I talk about that a bit in #1057. It can also crash if the value contains a function. The long term fix is that "trying to use equality on JS values should be a type error".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants