on master help sign in
make a really precise error for unexpected -> in declarations

Relevant to https://github.com/elm/error-message-catalog/issues/62

commit930d0de033f0e5eb36b5b87b3c46dc40b3ee8106 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 25 Jul 2019, 15:19 (7 years ago) parent1f4709f
1 file changed+54
compiler/src/Reporting/Error/Syntax.hs+54
compiler/src/Reporting/Error/Syntax.hs+54
@@ -2023,6 +2023,33 @@ toDeclDefReport source name declDef startRow startCol =
20232023 "This is a reserved word! Try using some other name?"
20242024 )
20252025
2026+ Code.Operator "->" ->
2027+ let
2028+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2029+ region = toWiderRegion row col 2
2030+ in
2031+ Report.Report "MISSING COLON?" region [] $
2032+ Code.toSnippet source surroundings (Just region)
2033+ (
2034+ D.reflow $
2035+ "I was not expecting to see an arrow here:"
2036+ ,
2037+ D.stack
2038+ [ D.fillSep
2039+ ["This","usually","means","a",D.green ":","is","missing","a","bit","earlier","in"
2040+ ,"a","type","annotation.","It","could","be","something","else","though,","so"
2041+ ,"here","is","a","valid","definition","for","reference:"
2042+ ]
2043+ , D.vcat
2044+ [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2045+ , D.fillSep [D.green "add","x","y","="]
2046+ , D.fillSep [" ","x","+","y"]
2047+ ]
2048+ , D.reflow $
2049+ "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
2050+ ]
2051+ )
2052+
20262053 Code.Operator op ->
20272054 let
20282055 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
@@ -3087,6 +3114,33 @@ toLetDefReport source name def startRow startCol =
30873114 "This is a reserved word! Try using some other name?"
30883115 )
30893116
3117+ Code.Operator "->" ->
3118+ let
3119+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3120+ region = toWiderRegion row col 2
3121+ in
3122+ Report.Report "MISSING COLON?" region [] $
3123+ Code.toSnippet source surroundings (Just region)
3124+ (
3125+ D.reflow $
3126+ "I was not expecting to see an arrow here:"
3127+ ,
3128+ D.stack
3129+ [ D.fillSep
3130+ ["This","usually","means","a",D.green ":","is","missing","a","bit","earlier","in"
3131+ ,"a","type","annotation.","It","could","be","something","else","though,","so"
3132+ ,"here","is","a","valid","definition","for","reference:"
3133+ ]
3134+ , D.vcat
3135+ [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3136+ , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3137+ , D.indent 6 $ D.fillSep ["x","+","y"]
3138+ ]
3139+ , D.reflow $
3140+ "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
3141+ ]
3142+ )
3143+
30903144 Code.Operator op ->
30913145 let
30923146 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)