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

Elm repl gives bad error messages for incorrect capitaliztion #345

Open YourFin opened 4 years ago

YourFin commented 4 years ago

Quick Summary: When capitalizing a value name in source file, the compiler gives a useful error message that suggests the same name in lower case. The repl, however, does not

SSCCE

Given Test.elm defined as following:

module Test exposing (..)

Foo = 12

If I try to compile Test.elm, I get the following error message:

-- UNEXPECTED CAPITAL LETTER ------------------------------------------ Test.elm

Declarations always start with a lower-case letter, so I am getting stuck here:

3| Foo = 12
   ^
Try a name like foo instead?

Note: Here are a couple valid declarations for reference:

    greet : String -> String
    greet name =
      "Hello " ++ name ++ "!"

    type User = Anonymous | LoggedIn String

Notice that they always start with a lower-case letter. Capitalization matters!

Which is amazing. Trying the same thing directly on the repl, however, gives this result:

> Foo = 12
|
-- UNEXPECTED EQUALS ------------------------------------------------------ REPL
I was not expecting to see this equals sign:

3|   Foo = 12
        ^
        Maybe you want == instead? To check if two values are equal?

    Note: I may be getting confused by your indentation. I think I am still parsing
        the `repl_input_value_` definition. Is this supposed to be part of a definition
        after that? If so, the problem may be a bit before the equals sign. I need all
        definitions to be indented exactly the same amount, so the problem may be that
        this new definition has too many spaces in front of it.

Which is not only confusing, and wrong advice, but I have to hit the enter key twice in order for the error to appear, which is confusing. I'm not sure how easy this would be to rectify, but I do know that it would be very confusing to a new programmer who doesn't understand that

  1. The pipe means that more input is needed to evaluate the input
  2. Therefore the first line has something wrong, as that one line looks like it should parse and evaluate on its own

Additional Details

It also appears that part of some of the repl internals leak with the "I think I am still parsing the repl_input_value_ definition." line.

I also admit that I only briefly looked at the relevant source, but it appears that this is a result of switching on the type of the parser output in attemptDeclOrExpr, rather than "running the compiler directly like on a source file" (I'm talking out of my ass here). Maybe this could be fixed by just verifying that the first token isn't capitalized when parsing a Parser.Declaration.Value?

I could be totally off track with that though.

github-actions[bot] commented 4 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.

YourFin commented 4 years ago

Ack, no, my suggestion would not work. I guess fixing this would require knowing if Foo is in scope or not to provide an intelligent suggestion.