Skip to content

Commit 9586e25

Browse files
committed
do a better job with errors for trailing commas in records
I detect if it is a trailing comma, and if not, I can give an error message that focuses on wanting a record field name next. That case probably will happen with upper case names, so I mention that specifically!
1 parent a051a17 commit 9586e25

File tree

1 file changed

+51
-11
lines changed

1 file changed

+51
-11
lines changed

compiler/src/Reporting/Error/Syntax.hs

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3892,22 +3892,42 @@ toRecordReport source context record startRow startCol =
38923892
]
38933893
)
38943894

3895-
_ ->
3895+
Code.Close _ '}' ->
38963896
let
38973897
surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
38983898
region = toRegion row col
38993899
in
3900-
Report.Report "UNFINISHED RECORD" region [] $
3900+
Report.Report "EXTRA COMMA" region [] $
39013901
Code.toSnippet source surroundings (Just region)
39023902
(
39033903
D.reflow $
39043904
"I am partway through parsing a record, but I got stuck here:"
39053905
,
39063906
D.stack
39073907
[ D.reflow $
3908-
"Trailing commas are not allowed in records, so I was expecting to see another\
3909-
\ record field defined next. If you are done defining the record, the fix may\
3910-
\ be to delete that last comma?"
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
3927+
["I","was","expecting","to","see","another","record","field","defined","next,"
3928+
,"so","I","am","looking","for","a","lower-case","name","like"
3929+
,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
3930+
]
39113931
, noteForRecordError
39123932
]
39133933
)
@@ -5277,22 +5297,42 @@ toTRecordReport source context record startRow startCol =
52775297
]
52785298
)
52795299

5280-
_ ->
5300+
Code.Close _ '}' ->
52815301
let
52825302
surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
52835303
region = toRegion row col
52845304
in
5285-
Report.Report "UNFINISHED RECORD TYPE" region [] $
5305+
Report.Report "EXTRA COMMA" region [] $
52865306
Code.toSnippet source surroundings (Just region)
52875307
(
52885308
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:"
52905310
,
52915311
D.stack
52925312
[ D.reflow $
5293-
"Trailing commas are not allowed in records, so I was expecting to see another\
5294-
\ record field defined next. If you are done defining the record, the fix may\
5295-
\ be to delete that last comma?"
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
5332+
["I","was","expecting","to","see","another","record","field","defined","next,"
5333+
,"so","I","am","looking","for","a","lower-case","name","like"
5334+
,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
5335+
]
52965336
, noteForRecordTypeError
52975337
]
52985338
)

0 commit comments

Comments
 (0)