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

Weird runtime error with eq #177

Closed
TheSeamau5 opened this Issue Feb 17, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@TheSeamau5
Contributor

TheSeamau5 commented Feb 17, 2015

So, I was testing the core String library with elm-check when suddenly I had a weird runtime error.

This is the code I was testing with:

module Test.String (tests) where

import String
import Char
import Check (..)
import Random (..)
import Random.Extra (..)
import Random.String (..)
import Random.Char (..)


consUnconsInverse : Char -> String -> Bool
consUnconsInverse char string =
  let nextString = String.cons char string
  in
    case String.uncons nextString of
      Nothing -> False
      Just (c, str) ->
        c == char && str == string

tests : List Property
tests =
  [ property2 "Consing and unconsing are inverse operations" consUnconsInverse unicode (rangeLengthWord 0 1000 unicode)
  ]

and when I try checking my test:

import Test.String as String
import Check (check)

import Text (plainText)

testResult =
  check String.tests

main =
  plainText testResult

I get a runtime error that seems to point to the eq function defined in Javascript

Chrome (latest) :

Cannot use 'in' operator to search for '0' in 饑


Open the developer console for more details.

Firefox Developer Edition (latest):

invalid 'in' operand y


Open the developer console for more details.

When I open the developer console, I'm immediately pointed to the eq function.

screen shot 2015-02-17 at 12 58 18 am

This is the moment right before the type error:

screen shot 2015-02-17 at 1 01 32 am

The bug happens due to a next if statement. It asks, if i in y except that the in operator only works on objects and somehow an actual string, in this case : , has managed to sneak in as y.

screen shot 2015-02-17 at 1 08 11 am

I speculate that what is needed is a typeof check for y the same way that there is a typeof check for x cuz typeof "饑" === "object" yields false

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jun 25, 2016

Member

Thank you for the comprehensive issue! Love issues like this :)

This should be fixed by 6f5fbb8.

Member

evancz commented Jun 25, 2016

Thank you for the comprehensive issue! Love issues like this :)

This should be fixed by 6f5fbb8.

@evancz evancz closed this Jun 25, 2016

evancz added a commit that referenced this issue Jun 25, 2016

Add more tests of equality
Add case from #177 about unicode Chars and for tricky data structures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment