on master help sign in
improve error message for bad declaration starts

Improvement based on https://github.com/elm/error-message-catalog/issues/163

commitef457e759bb50601fc680eb3f38946fa65dfe3a4 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 25 Jul 2019, 17:05 (7 years ago) parentc0e8583
1 file changed+14−6
compiler/src/Reporting/Error/Syntax.hs+14−6
compiler/src/Reporting/Error/Syntax.hs+14−6
@@ -1407,12 +1407,20 @@ toDeclarationsReport source decl =
14071407 Code.toSnippet source region Nothing
14081408 (
14091409 D.reflow $
1410− "I was expecting to see a new declaration here:"
1410+ "I was expecting to see a declaration, but I am getting stuck here:"
14111411 ,
14121412 D.stack
1413− [ D.reflow $
1414− "I am not sure what is going wrong exactly, but here are a couple valid\
1415− \ declarations for reference:"
1413+ [ case Code.whatIsNext source row col of
1414+ Code.Other (Just char) | Char.isUpper char ->
1415+ D.reflow $
1416+ "All declarations start with lower-case letters in Elm, so maybe this letter can\
1417+ \ be changed to lower-case?"
1418+
1419+ _ ->
1420+ D.reflow $
1421+ "Declarations normally start with a lower-case name or the `type` keyword."
1422+ , D.toSimpleHint $
1423+ "Here are a couple valid declarations for reference:"
14161424 , D.vcat
14171425 [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
14181426 , D.fillSep [D.green "add","x","y","="]
@@ -1420,8 +1428,8 @@ toDeclarationsReport source decl =
14201428 ]
14211429 , D.fillSep [D.cyan "type",D.green "User","=","Anonymous","|","LoggedIn String"]
14221430 , D.reflow $
1423− "Note that all declarations start with lower-case letters in Elm. Capitalization\
1424− \ makes a difference, so be conscious of that if you are working from examples!"
1431+ "Notice that these declarations start with lower-case letters. Capitalization\
1432+ \ makes a difference in Elm!"
14251433 ]
14261434 )
14271435