evancz / url-parser

Parse URLs into nicely structured data
http://package.elm-lang.org/packages/evancz/url-parser/latest/
BSD 3-Clause "New" or "Revised" License
114 stars 29 forks source link

Self-referential type error when parsing (s "") #31

Closed hamnox closed 7 years ago

hamnox commented 7 years ago

Mac OS X El capitan (10.11.6), elm v0.18.0, url-parser v2.0.1

Self-referential type error when parsing (s "")

This bug originally surfaced as the compiler mysteriously stalling as soon as I added a test for an empty hash. Repl gave me a more useful error.

From previous issues like #21 , it looks like the proper way to accomplish what I wanted is with 'top'. The fact that this bug was silent, though, worries me.

> import UrlParser exposing (s)
> UrlParser.parseHash (s "")
-- INFINITE TYPE --------------------------------------------- repl-temp-000.elm

I am inferring a weird self-referential type for `d_e_l_t_r_o_n_3_0_3_0`

3| d_e_l_t_r_o_n_3_0_3_0 =
   ^^^^^^^^^^^^^^^^^^^^^
Here is my best effort at writing down the type. You will see ? and ∞ for parts
of the type that repeat something already printed out infinitely.

    Navigation.Location -> Maybe ?

Usually staring at the type is not so helpful in these cases, so definitely read
the debugging hints for ideas on how to figure this out:
<https://github.com/elm-lang/elm-compiler/blob/0.18.0/hints/infinite-type.md>
process-bot commented 7 years ago

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 commented 7 years ago

The parseHash function has this type:

parseHash : Parser (a -> a) a -> Location -> Maybe a

The s function has this type:

s : String -> Parser a a

So s "" : Parser a a and when it is given to parseHash it needs to be unified with Parser (a -> a) a. That leads to an infinite type if a -> a must be the same as a. So this error seems to be describing the problem exactly.

With 0.18, you can see the compiler fail on certain infinite types. This is fixed with the dev version of the compiler, so it'll be fixed in the next release. I believe that is the root issue here.