on master help sign in
do a better job with errors for trailing commas in records
9586e25Evan Czaplicki
compiler/src/Reporting/Error/Syntax.hs+51−11
@@ -3892,12 +3892,12 @@ toRecordReport source context record startRow startCol =
3892 ]
3892 ]
3893 )
3893 )
3894
3894
3895− _ ->
3895+ Code.Close _ '}' ->
3896 let
3896 let
3897 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3897 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3898 region = toRegion row col
3898 region = toRegion row col
3899 in
3899 in
3900− Report.Report "UNFINISHED RECORD" region [] $
3900+ Report.Report "EXTRA COMMA" region [] $
3901 Code.toSnippet source surroundings (Just region)
3901 Code.toSnippet source surroundings (Just region)
3902 (
3902 (
3903 D.reflow $
3903 D.reflow $
@@ -3905,9 +3905,29 @@ toRecordReport source context record startRow startCol =
3905 ,
3905 ,
3906 D.stack
3906 D.stack
3907 [ D.reflow $
3907 [ D.reflow $
3908− "Trailing commas are not allowed in records, so I was expecting to see another\
3908+ "Trailing commas are not allowed in records. Try deleting the comma that appears\
3909+ \ before this closing curly brace."
3910+ , noteForRecordError
3911+ ]
3912+ )
3913+
3914+ _ ->
3915+ let
3916+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3917+ region = toRegion row col
3918+ in
3919+ Report.Report "PROBLEM IN RECORD" region [] $
3920+ Code.toSnippet source surroundings (Just region)
3921+ (
3922+ D.reflow $
3923+ "I am partway through parsing a record, but I got stuck here:"
3924+ ,
3925+ D.stack
3926+ [ D.fillSep
3909− \ record field defined next. If you are done defining the record, the fix may\
3927+ ["I","was","expecting","to","see","another","record","field","defined","next,"
3910− \ be to delete that last comma?"
3928+ ,"so","I","am","looking","for","a","lower-case","name","like"
3929+ ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
3930+ ]
3911 , noteForRecordError
3931 , noteForRecordError
3912 ]
3932 ]
3913 )
3933 )
@@ -5277,22 +5297,42 @@ toTRecordReport source context record startRow startCol =
5277 ]
5297 ]
5278 )
5298 )
5279
5299
5280− _ ->
5300+ Code.Close _ '}' ->
5281 let
5301 let
5282 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5302 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5283 region = toRegion row col
5303 region = toRegion row col
5284 in
5304 in
5285− Report.Report "UNFINISHED RECORD TYPE" region [] $
5305+ Report.Report "EXTRA COMMA" region [] $
5286 Code.toSnippet source surroundings (Just region)
5306 Code.toSnippet source surroundings (Just region)
5287 (
5307 (
5288 D.reflow $
5308 D.reflow $
5289− "I am partway through parsing a record type, but I got stuck after that last comma:"
5309+ "I am partway through parsing a record type, but I got stuck here:"
5290 ,
5310 ,
5291 D.stack
5311 D.stack
5292 [ D.reflow $
5312 [ D.reflow $
5293− "Trailing commas are not allowed in records, so I was expecting to see another\
5313+ "Trailing commas are not allowed in record types. Try deleting the comma that\
5314+ \ appears before this closing curly brace."
5315+ , noteForRecordTypeError
5316+ ]
5317+ )
5318+
5319+ _ ->
5320+ let
5321+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5322+ region = toRegion row col
5323+ in
5324+ Report.Report "PROBLEM IN RECORD TYPE" region [] $
5325+ Code.toSnippet source surroundings (Just region)
5326+ (
5327+ D.reflow $
5328+ "I am partway through parsing a record type, but I got stuck here:"
5329+ ,
5330+ D.stack
5331+ [ D.fillSep
5294− \ record field defined next. If you are done defining the record, the fix may\
5332+ ["I","was","expecting","to","see","another","record","field","defined","next,"
5295− \ be to delete that last comma?"
5333+ ,"so","I","am","looking","for","a","lower-case","name","like"
5334+ ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
5335+ ]
5296 , noteForRecordTypeError
5336 , noteForRecordTypeError
5297 ]
5337 ]
5298 )
5338 )