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

Runtime error when comparing nested Html of different depths #694

Closed
lpil opened this Issue Aug 18, 2016 · 4 comments

Comments

Projects
None yet
4 participants
@lpil

lpil commented Aug 18, 2016

Hello!

Today while trying to do some testing I encounted a runtime error. Here's a recreation.

> import Html exposing (..)
> (div [] []) == (div [] [])
-- True : Bool

> (div [] [ text "Hi" ]) == (div [] [ text "Hello" ])
-- False : Bool

> (div [] [ text "Hi" ]) == (div [] [])
-- TypeError: Cannot read property 'type' of undefined

Elm version 0.17.0, installed via the elm package on npm.

Debian Jessie Linux OS.

Running Elm in node v4.1.1 via the REPL.

Here are the entries from my elm-stuff/exact-dependencies.json.

    "elm-lang/html": "1.1.0",
    "elm-lang/core": "4.0.4"

I was pointed over here from elm/compiler#1465

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Aug 18, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Aug 18, 2016

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Aug 29, 2016

Member

Equality is not defined on virtual DOM values, so the fix is going to be modifying the compiler to detect when folks try to use equality in invalid cases (like on functions) and making that an error at compile time. This is already planned, so I'd rather not track the implications of that change here.

Member

evancz commented Aug 29, 2016

Equality is not defined on virtual DOM values, so the fix is going to be modifying the compiler to detect when folks try to use equality in invalid cases (like on functions) and making that an error at compile time. This is already planned, so I'd rather not track the implications of that change here.

@evancz evancz closed this Aug 29, 2016

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Aug 30, 2016

Contributor

But maybe at least mentioning this in the core documentation would be good? Currently, http://package.elm-lang.org/packages/elm-lang/core/4.0.5/Basics#== carries this note:

Note: Equality (in the Elm sense) is not possible for certain types. For example, the functions (\n -> n + 1) and (\n -> 1 + n) are “the same” but detecting this in general is undecidable. In a future release, the compiler will detect when (==) is used with problematic types and provide a helpful error message. This will require quite serious infrastructure work that makes sense to batch with another big project, so the stopgap is to crash as quickly as possible. Problematic types include functions and JavaScript values like Json.Encode.Value which could contain functions if passed through a port.

That html values are also of "problematic type" seems important information for users, since trying to test views by comparing html values via == is something that is quite tempting. Currently neither the documentation for core nor for the html package tell users that using == on html values is not okay.

Contributor

jvoigtlaender commented Aug 30, 2016

But maybe at least mentioning this in the core documentation would be good? Currently, http://package.elm-lang.org/packages/elm-lang/core/4.0.5/Basics#== carries this note:

Note: Equality (in the Elm sense) is not possible for certain types. For example, the functions (\n -> n + 1) and (\n -> 1 + n) are “the same” but detecting this in general is undecidable. In a future release, the compiler will detect when (==) is used with problematic types and provide a helpful error message. This will require quite serious infrastructure work that makes sense to batch with another big project, so the stopgap is to crash as quickly as possible. Problematic types include functions and JavaScript values like Json.Encode.Value which could contain functions if passed through a port.

That html values are also of "problematic type" seems important information for users, since trying to test views by comparing html values via == is something that is quite tempting. Currently neither the documentation for core nor for the html package tell users that using == on html values is not okay.

@lpil

This comment has been minimized.

Show comment
Hide comment
@lpil

lpil Aug 30, 2016

A compiler error and improved documentation would be wonderful, thanks all.

Given we cannot test equality on html is there another method for testing views? Often I have business logic that results in html that I would love to be able to test.

lpil commented Aug 30, 2016

A compiler error and improved documentation would be wonderful, thanks all.

Given we cannot test equality on html is there another method for testing views? Often I have business logic that results in html that I would love to be able to test.

@kress95 kress95 referenced this issue May 2, 2017

Merged

Add Browser Model #81

6 of 10 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment