on master help sign in
Add errors for `as` patterns with missing aliases
374bf9aEvan Czaplicki
compiler/src/Reporting/Error/Syntax.hs+46−2
@@ -2980,7 +2980,29 @@ toPatternReport source context pattern startRow startCol =
2980 )
2980 )
2981
2981
2982 PAlias row col ->
2982 PAlias row col ->
2983− error "TODO PAlias" row col
2983+ let
2984+ region = toRegion row col
2985+ in
2986+ Report.Report "UNFINISHED PATTERN" region [] $
2987+ Code.toSnippet source region Nothing $
2988+ (
2989+ D.reflow $
2990+ "I was expecting to see a variable name after the `as` keyword:"
2991+ ,
2992+ D.stack
2993+ [ D.fillSep $
2994+ ["The","`as`","keyword","lets","you","write","patterns","like"
2995+ ,"((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")"
2996+ ,"so","you","can","refer","to","individual","parts","of","the","tuple","with"
2997+ ,D.dullyellow "x","and",D.dullyellow "y","or","you","refer","to","the","whole"
2998+ ,"thing","with",D.dullyellow "point."
2999+ ]
3000+ , D.reflow $
3001+ "So I was expecting to see a variable name after the `as` keyword here. Sometimes\
3002+ \ people just want to use `as` as a variable name though. Try using a different name\
3003+ \ in that case!"
3004+ ]
3005+ )
2984
3006
2985 PWildcardNotVar name width row col ->
3007 PWildcardNotVar name width row col ->
2986 let
3008 let
@@ -3009,7 +3031,29 @@ toPatternReport source context pattern startRow startCol =
3009 error "TODO PIndentStart" row col
3031 error "TODO PIndentStart" row col
3010
3032
3011 PIndentAlias row col ->
3033 PIndentAlias row col ->
3012− error "TODO PIndentAlias" row col
3034+ let
3035+ region = toRegion row col
3036+ in
3037+ Report.Report "UNFINISHED PATTERN" region [] $
3038+ Code.toSnippet source region Nothing $
3039+ (
3040+ D.reflow $
3041+ "I was expecting to see a variable name after the `as` keyword:"
3042+ ,
3043+ D.stack
3044+ [ D.fillSep $
3045+ ["The","`as`","keyword","lets","you","write","patterns","like"
3046+ ,"((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")"
3047+ ,"so","you","can","refer","to","individual","parts","of","the","tuple","with"
3048+ ,D.dullyellow "x","and",D.dullyellow "y","or","you","refer","to","the","whole"
3049+ ,"thing","with",D.dullyellow "point."
3050+ ]
3051+ , D.reflow $
3052+ "So I was expecting to see a variable name after the `as` keyword here. Sometimes\
3053+ \ people just want to use `as` as a variable name though. Try using a different name\
3054+ \ in that case!"
3055+ ]
3056+ )
3013
3057
3014
3058
3015toPRecordReport :: Code.Source -> PRecord -> Row -> Col -> Report.Report
3059toPRecordReport :: Code.Source -> PRecord -> Row -> Col -> Report.Report