Skip to content

Commit d3539ef

Browse files
authored
Dedicated error for dict literal spread (#7901)
* dedicated error for dict literal spread * fix and changelog
1 parent a631b38 commit d3539ef

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#### :nail_care: Polish
3232

3333
- Add (dev-)dependencies to build schema. https://github.com/rescript-lang/rescript/pull/7892
34+
- Dedicated error for dict literal spreads. https://github.com/rescript-lang/rescript/pull/7901
3435

3536
#### :house: Internal
3637

compiler/syntax/src/res_core.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ module ErrorMessages = struct
9797
...b}` wouldn't make sense, as `b` would override every field of `a` \
9898
anyway."
9999

100+
let dict_expr_spread = "Dict literals do not support spread (`...`) yet."
101+
100102
let variant_ident =
101103
"A polymorphic variant (e.g. #id) must start with an alphabetical letter \
102104
or be a number (e.g. #742)"
@@ -3368,6 +3370,12 @@ and parse_record_expr_row p :
33683370

33693371
and parse_dict_expr_row p =
33703372
match p.Parser.token with
3373+
| DotDotDot ->
3374+
Parser.err p (Diagnostics.message ErrorMessages.dict_expr_spread);
3375+
Parser.next p;
3376+
(* Parse the expr so it's consumed *)
3377+
let _spread_expr = parse_constrained_or_coerced_expr p in
3378+
None
33713379
| String s -> (
33723380
let loc = mk_loc p.start_pos p.end_pos in
33733381
Parser.next p;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let x = dict{...foo, "bar": 3}
2+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
Syntax error!
3+
syntax_tests/data/parsing/errors/other/dict_spread.res:1:14-16
4+
5+
1 │ let x = dict{...foo, "bar": 3}
6+
2 │
7+
3 │
8+
9+
Dict literals do not support spread (`...`) yet.
10+
11+
let x = Primitive_dict.make [|("bar", 3)|]

0 commit comments

Comments
 (0)