on master help sign in
improve error message when keyword used as variable
4b6e598Evan Czaplicki
compiler/src/Reporting/Error/Syntax.hs+42−8
@@ -2016,11 +2016,28 @@ toDeclDefReport source name declDef startRow startCol =
2016 Report.Report "RESERVED WORD" region [] $
2016 Report.Report "RESERVED WORD" region [] $
2017 Code.toSnippet source surroundings (Just region)
2017 Code.toSnippet source surroundings (Just region)
2018 (
2018 (
2019− D.reflow $
2019+ D.fillSep
2020− "It looks like you are trying to use `" ++ keyword ++ "` as an argument:"
2020+ ["The","name"
2021+ ,"`" <> D.cyan (D.fromChars keyword) <> "`"
2022+ ,"is","reserved","in","Elm,","so","it","cannot"
2023+ ,"be","used","as","an","argument","here:"
2024+ ]
2021 ,
2025 ,
2026+ D.stack
2022− D.reflow $
2027+ [ D.reflow $
2023− "This is a reserved word! Try using some other name?"
2028+ "Try renaming it to something else."
2029+ , case keyword of
2030+ "as" ->
2031+ D.toFancyNote
2032+ ["This","keyword","is","reserved","for","pattern","matches","like"
2033+ ,"((x,y)",D.cyan "as","point)","where","you","want","to","name","a","tuple","and"
2034+ ,"the","values","it","contains."
2035+ ]
2036+
2037+ _ ->
2038+ D.toSimpleNote $
2039+ "The `" ++ keyword ++ "` keyword has a special meaning in Elm, so it can only be used in certain situations."
2040+ ]
2024 )
2041 )
2025
2042
2026 Code.Operator "->" ->
2043 Code.Operator "->" ->
@@ -3107,11 +3124,28 @@ toLetDefReport source name def startRow startCol =
3107 Report.Report "RESERVED WORD" region [] $
3124 Report.Report "RESERVED WORD" region [] $
3108 Code.toSnippet source surroundings (Just region)
3125 Code.toSnippet source surroundings (Just region)
3109 (
3126 (
3110− D.reflow $
3127+ D.fillSep
3111− "It looks like you are trying to use `" ++ keyword ++ "` as an argument:"
3128+ ["The","name"
3129+ ,"`" <> D.cyan (D.fromChars keyword) <> "`"
3130+ ,"is","reserved","in","Elm,","so","it","cannot"
3131+ ,"be","used","as","an","argument","here:"
3132+ ]
3112 ,
3133 ,
3134+ D.stack
3113− D.reflow $
3135+ [ D.reflow $
3114− "This is a reserved word! Try using some other name?"
3136+ "Try renaming it to something else."
3137+ , case keyword of
3138+ "as" ->
3139+ D.toFancyNote
3140+ ["This","keyword","is","reserved","for","pattern","matches","like"
3141+ ,"((x,y)",D.cyan "as","point)","where","you","want","to","name","a","tuple","and"
3142+ ,"the","values","it","contains."
3143+ ]
3144+
3145+ _ ->
3146+ D.toSimpleNote $
3147+ "The `" ++ keyword ++ "` keyword has a special meaning in Elm, so it can only be used in certain situations."
3148+ ]
3115 )
3149 )
3116
3150
3117 Code.Operator "->" ->
3151 Code.Operator "->" ->