elm / error-message-catalog

A catalog of broken Elm programs / data to improve error messages
BSD 3-Clause "New" or "Revised" License
173 stars 17 forks source link

Missing else conditional gives whitespace error #251

Closed stevensonmt closed 5 years ago

stevensonmt commented 6 years ago
view : Model -> Html Msg
view model =
  if subToggle then
    let
        angle =
          turns (Time.inMinutes model)

        handX =
          toString (50 + 40 * cos angle)

        handY =
          toString (50 + 40 * sin angle)
    in
       svg [ viewBox "0 0 100 100", width "300px" ]
       [ circle [ cx "50", cy "50", r "45", fill "#0B79CE" ] []
       , line [ x1 "50", y1 "50", x2 handX, y2 handY, stroke "#023963" ] []
       ]

This won't compile and complains of:

I need whitespace, but got stuck on what looks like a new declaration. You are
either missing some stuff in the declaration above or just need to add some
spaces here:

I am looking for one of the following things:

    whitespace

What it really needs is an else statement though.

evancz commented 5 years ago

Thank you for the report! I am wrapping up an overhaul of the parser that has better error messages. For your example, the error is now:

-- UNFINISHED IF ------------------------------------------------------ temp.elm

I was expecting to see an `else` branch after this:

 3|   if subToggle then
 4|     let
 5|         angle =
 6|           turns (Time.inMinutes model)
 7| 
 8|         handX =
 9|           toString (50 + 40 * cos angle)
10| 
11|         handY =
12|           toString (50 + 40 * sin angle)
13|     in
14|        svg [ viewBox "0 0 100 100", width "300px" ]
15|        [ circle [ cx "50", cy "50", r "45", fill "#0B79CE" ] []
16|        , line [ x1 "50", y1 "50", x2 handX, y2 handY, stroke "#023963" ] []
17|        ]
            ^
I know what to do when the condition is `True`, but not when it is `False`.

Add an else branch to handle that scenario!

This should become available when Elm 0.19.1 is released. Thanks again for reporting this case!