I have found a weird type-checking issue after self-referencing a function in Elm 0.19. The following code compiles and produces a runtime error:
module Main exposing (main)
import Html exposing (Html)
sscce : a -> Html msg
sscce anything =
let
thisDefinitionBreaksThings =
sscce
in
anything "whoops!" "This should not compile" 3 4 112 () []
main : Html msg
main =
sscce ()
This same example does not compile in Elm 0.18, producing the expected error:
`anything` is not a function, but you are giving it 7 arguments!
Maybe you forgot some parentheses? Or a comma?
It looks like Elm stops type-checking anything after the function references itself and then allows me to do whatever I want with it (?).
I simplified this SSCCE:
module Main exposing (main)
import Html
f : a -> Html.Html b
f a =
a f
main =
f ()
If I remove the type definition of f, it won't compile and show the correct error.
But with the type definition it crashes at runtime.
Both of these SSCCEs are really excellent! Thank you!
With the changes in https://github.com/elm/compiler/commit/af37341a2969ed5a8391adb95cf094e24673c2d7, I am getting the following errors for the examples you provided:
-- TOO MANY ARGS ------------------------------------------------------ temp.elm
The `anything` value is not a function, but it was given 7 arguments.
8| anything "whoops!" "This should not compile" 3 4 112 () []
^^^^^^^^
Are there any missing commas? Or missing parentheses?
-- TOO MANY ARGS ------------------------------------------------------ temp.elm
The `a` value is not a function, but it was given 1 argument.
16| a f
^
Are there any missing commas? Or missing parentheses?
Most helpful comment
Both of these SSCCEs are really excellent! Thank you!
With the changes in https://github.com/elm/compiler/commit/af37341a2969ed5a8391adb95cf094e24673c2d7, I am getting the following errors for the examples you provided: