Skip to content
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

Case statement with wrong indents could give better hints #225

Closed
dmag opened this issue Jul 10, 2017 · 1 comment

Comments

@dmag
Copy link

commented Jul 10, 2017

I had a working program (elm 0.18.0), and tried to add a simple NoOp branch to my update function. I was doing a copy-paste, which accidentally added an extra space.

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
  case msg of
    Name name ->
      ( { model | name = name }, Cmd.none )
     NoOp ->
      ( model, Cmd.none )

The compiler gave me this error, which was quite confusing.

-- SYNTAX PROBLEM --------------------------------------------- ./src/Update.elm

Arrows are reserved for cases and anonymous functions. Maybe you want > or >=
instead?

30|      NoOp ->
              ^
Maybe <http://elm-lang.org/docs/syntax> can help you figure it out.

Detected errors in 1 module.                                        

It would have helped if the compiler saw the arrow and gave a hint: "if was supposed to be part of your existing case statement, it's not indented properly." For completeness, if you have too little indent, you get this error, which could use a similar heuristic to give the same hint.

-- SYNTAX PROBLEM --------------------------------------------- ./src/Update.elm

I ran into something unexpected when parsing your code!

30|   NoOp ->
      ^
I am looking for one of the following things:

    end of input
    whitespace
@evancz

This comment has been minimized.

Copy link
Member

commented Jul 25, 2019

Thank you for reporting this! I am finishing up a revamp of the compiler that is able to produce much nicer error messages. Based on your example, I made a tweak in elm/compiler@aaa2d65 to make the message super relevant! My development build is producing:

-- UNEXPECTED ARROW --------------------------------------------------- temp.elm

I am parsing a `case` expression right now, but this arrow is confusing me:

6|      NoOp ->
             ^^
It makes sense to see arrows around here, so I suspect it is something earlier.
Maybe this pattern is indented a bit farther than the previous patterns?

Note: Sometimes I get confused by indentation, so try to make your `case` look
something like this:

    case maybeWidth of
      Just width ->
        width + 200

      Nothing ->
        400

Notice the indentation! Patterns are aligned with each other. Same indentation.
The expressions after each arrow are all indented a bit more than the patterns.
That is important!

Thank you for reporting this! It makes it really easy to check if the error message is giving information that is relevant to the reader!

@evancz evancz closed this Jul 25, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.