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

`(==)` does not work correctly on records with field named `ctor` #652

Closed
jvoigtlaender opened this Issue Jul 1, 2016 · 9 comments

Comments

Projects
None yet
3 participants
@jvoigtlaender
Contributor

jvoigtlaender commented Jul 1, 2016

The current version of core (the current master branch) evaluates {ctor = [0]} == {ctor = [0]} to False.

@evancz, probably caused by the recent refactoring in elm-lang@6f5fbb8?

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Jul 1, 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 Jul 1, 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.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jul 12, 2016

Contributor

Update: This now also happens with the released version 4.0.2 of core.

That is, the following program wrongly outputs False:

import Html

main = Html.text (toString ({ctor = [0]} == {ctor = [0]}))

while the following program continues to correctly output True:

import Html

main = Html.text (toString ({field = [0]} == {field = [0]}))

@evancz, just to let you know that the bug-fix release of core also introduced a bug. This one, which wasn't present in version 4.0.1.

Contributor

jvoigtlaender commented Jul 12, 2016

Update: This now also happens with the released version 4.0.2 of core.

That is, the following program wrongly outputs False:

import Html

main = Html.text (toString ({ctor = [0]} == {ctor = [0]}))

while the following program continues to correctly output True:

import Html

main = Html.text (toString ({field = [0]} == {field = [0]}))

@evancz, just to let you know that the bug-fix release of core also introduced a bug. This one, which wasn't present in version 4.0.1.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jul 12, 2016

Member

The bigger (timely) fix will be to reintroduce the hidden _ field to Elm records. This will serve as a runtime tag of whether something is an Elm record a union type or a JS value. That will fix some issues where toString will show JS values instead of <internal value> or something.

I feel like you found this by reading the new code, not by having a field with that name, so I'm not certain how urgent this is. That said, I suspect there is a stopgap fix that does not slow things down too much. Perhaps even just doing the non-pseudo-code of switching to eqHelp(ctor, ctor) to compare the values. A bit slower, but probably fine compared to the previous version.

Member

evancz commented Jul 12, 2016

The bigger (timely) fix will be to reintroduce the hidden _ field to Elm records. This will serve as a runtime tag of whether something is an Elm record a union type or a JS value. That will fix some issues where toString will show JS values instead of <internal value> or something.

I feel like you found this by reading the new code, not by having a field with that name, so I'm not certain how urgent this is. That said, I suspect there is a stopgap fix that does not slow things down too much. Perhaps even just doing the non-pseudo-code of switching to eqHelp(ctor, ctor) to compare the values. A bit slower, but probably fine compared to the previous version.

@evancz evancz closed this in 176e8f8 Jul 12, 2016

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jul 12, 2016

Contributor

No, I didn't find this by reading the code. I found it by trying to run the test suite. Note that it contains this (at https://github.com/elm-lang/core/blob/master/tests/Test/Equality.elm#L22):

        , test "ctor same" <| assert ({ctor = Just 3} == {ctor = Just 3})

From there, I was trying whether it has something to do especially with Just of Maybe, which was not the case...

Only after that, I checked the source code to see what other special handling goes on with the ctor field name, and encountered this other failure, with toString: https://github.com/elm-lang/core/issues/654.

As an aside, it's a pity that the test suite is currently failing on GitHub.

Contributor

jvoigtlaender commented Jul 12, 2016

No, I didn't find this by reading the code. I found it by trying to run the test suite. Note that it contains this (at https://github.com/elm-lang/core/blob/master/tests/Test/Equality.elm#L22):

        , test "ctor same" <| assert ({ctor = Just 3} == {ctor = Just 3})

From there, I was trying whether it has something to do especially with Just of Maybe, which was not the case...

Only after that, I checked the source code to see what other special handling goes on with the ctor field name, and encountered this other failure, with toString: https://github.com/elm-lang/core/issues/654.

As an aside, it's a pity that the test suite is currently failing on GitHub.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jul 12, 2016

Member

I'm working on the tests. You can try sleuthing too if you'd like.

Member

evancz commented Jul 12, 2016

I'm working on the tests. You can try sleuthing too if you'd like.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jul 12, 2016

Contributor

I see you got the test suite passing already. A nice green batch on the repo page. Cool!

Maybe it's worth merging https://github.com/elm-lang/core/pull/655. It should pass now, given your earlier stopgap fix. And it might serve as a prophylaxis against any special casing surrounding ctor and equality testing creeping back in as an error at some point in the future.

Or if you think that's unlikely to become a problem again, that pull request could be simply closed.

Contributor

jvoigtlaender commented Jul 12, 2016

I see you got the test suite passing already. A nice green batch on the repo page. Cool!

Maybe it's worth merging https://github.com/elm-lang/core/pull/655. It should pass now, given your earlier stopgap fix. And it might serve as a prophylaxis against any special casing surrounding ctor and equality testing creeping back in as an error at some point in the future.

Or if you think that's unlikely to become a problem again, that pull request could be simply closed.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jul 12, 2016

Member

Given that people in JS world get pretty intense about what color that badge is, I don't think it makes sense to check in broken tests unfortunately. I'd expect a relatively long turn-around on the _ stopgap because it needs the compiler to change, so I would not want things to be "red" for that amount of time.

Member

evancz commented Jul 12, 2016

Given that people in JS world get pretty intense about what color that badge is, I don't think it makes sense to check in broken tests unfortunately. I'd expect a relatively long turn-around on the _ stopgap because it needs the compiler to change, so I would not want things to be "red" for that amount of time.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jul 12, 2016

Contributor

If I understand correctly what you did two hours ago, the tests from https://github.com/elm-lang/core/pull/655 will not prevent the badge from being green. They were broken tests, but no longer.

Contributor

jvoigtlaender commented Jul 12, 2016

If I understand correctly what you did two hours ago, the tests from https://github.com/elm-lang/core/pull/655 will not prevent the badge from being green. They were broken tests, but no longer.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jul 12, 2016

Member

Ah, gotcha. I thought you meant about ctor problems with toString. I started the tests again. Will merge if green. Thanks!

Member

evancz commented Jul 12, 2016

Ah, gotcha. I thought you meant about ctor problems with toString. I started the tests again. Will merge if green. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment