Skip to content

Commit

Permalink
Merge pull request elm#1031 from Skinney/fix-list-equality
Browse files Browse the repository at this point in the history
Fixes runtime exception when comparing inequal lists with over 100 elements
  • Loading branch information
evancz authored Nov 13, 2019
2 parents d90b7ae + 1eec0e1 commit d95e1f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/Elm/Kernel/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ function _Utils_eq(x, y)

function _Utils_eqHelp(x, y, depth, stack)
{
if (depth > 100)
{
stack.push(_Utils_Tuple2(x,y));
return true;
}

if (x === y)
{
return true;
Expand All @@ -43,6 +37,12 @@ function _Utils_eqHelp(x, y, depth, stack)
return false;
}

if (depth > 100)
{
stack.push(_Utils_Tuple2(x,y));
return true;
}

/**__DEBUG/
if (x.$ === 'Set_elm_builtin')
{
Expand Down
14 changes: 12 additions & 2 deletions tests/tests/Test/Equality.elm
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module Test.Equality exposing (tests)

import Basics exposing (..)
import Expect
import Fuzz
import Maybe exposing (..)
import Test exposing (..)
import Expect


type Different
Expand All @@ -30,5 +31,14 @@ tests =
, test "ctor diff" <| \() -> Expect.equal True ({ field = Just 3 } /= { field = Nothing })
, test "ctor diff, special case" <| \() -> Expect.equal True ({ ctor = Just 3 } /= { ctor = Nothing })
]

listTests =
describe "List equality"
[ fuzz2 (Fuzz.intRange 100 10000) (Fuzz.intRange 100 10000) "Simple comparison" <|
\size1 size2 ->
Expect.equal
(size1 == size2)
(List.range 0 size1 == List.range 0 size2)
]
in
describe "Equality Tests" [ diffTests, recordTests ]
describe "Equality Tests" [ diffTests, recordTests, listTests ]

0 comments on commit d95e1f3

Please sign in to comment.