This repository was archived by the owner on Jun 15, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +42
-1
lines changed
tests/parsing/errors/typeDef Expand file tree Collapse file tree 4 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -4024,6 +4024,14 @@ and parseStringFieldDeclaration p =
4024
4024
Parser. expect ~grammar: Grammar. TypeExpression Colon p;
4025
4025
let typ = parsePolyTypeExpr p in
4026
4026
Some (Parsetree. Otag (fieldName, attrs, typ))
4027
+ | Lident name ->
4028
+ let nameLoc = mkLoc p.startPos p.endPos in
4029
+ Parser. err p (Diagnostics. message " An inline record type declaration is only allowed in a variant constructor's declaration" );
4030
+ Parser. next p;
4031
+ let fieldName = Location. mkloc name nameLoc in
4032
+ Parser. expect ~grammar: Grammar. TypeExpression Colon p;
4033
+ let typ = parsePolyTypeExpr p in
4034
+ Some (Parsetree. Otag (fieldName, attrs, typ))
4027
4035
| _token ->
4028
4036
None
4029
4037
Original file line number Diff line number Diff line change @@ -209,7 +209,7 @@ let isParameterStart = function
209
209
210
210
(* TODO: overparse Uident ? *)
211
211
let isStringFieldDeclStart = function
212
- | Token. String _ | At -> true
212
+ | Token. String _ | Lident _ | At -> true
213
213
| _ -> false
214
214
215
215
(* TODO: overparse Uident ? *)
Original file line number Diff line number Diff line change @@ -35,6 +35,30 @@ type nonrec record = {
35
35
A record needs at least one field
36
36
37
37
38
+ ========================================================"
39
+ ` ;
40
+
41
+ exports [` inlineRecord.res 1` ] = `
42
+ "=====Parsetree==========================================
43
+ type nonrec entity =
44
+ | Director
45
+ | Student of
46
+ {
47
+ name : string ;
48
+ reportCard : < passing : bool ;score : int > Js .t }
49
+ =====Errors=============================================
50
+
51
+ Syntax error!
52
+ parsing/errors/typeDef/inlineRecord.res 6:9-15
53
+ 4 ┆ name: string,
54
+ 5 ┆ reportCard: {
55
+ 6 ┆ passing : bool ,
56
+ 7 ┆ score : int
57
+ 8 ┆ }
58
+
59
+ An inline record type declaration is only allowed in a variant constructor's declaration
60
+
61
+
38
62
========================================================"
39
63
` ;
40
64
Original file line number Diff line number Diff line change
1
+ type entity =
2
+ | Director
3
+ | Student ({
4
+ name : string ,
5
+ reportCard : {
6
+ passing : bool ,
7
+ score : int
8
+ }
9
+ })
You can’t perform that action at this time.
0 commit comments