Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#### :nail_care: Polish

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

#### :house: Internal

Expand Down
8 changes: 8 additions & 0 deletions compiler/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ module ErrorMessages = struct
...b}` wouldn't make sense, as `b` would override every field of `a` \
anyway."

let dict_expr_spread = "Dict literals do not support spread (`...`) yet."
Copy link
Member

@nojaf nojaf Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit of a stretch, but we could sneak in a link to a GitHub issue folks can upvote. That gives an indication how many people have tried this.


let variant_ident =
"A polymorphic variant (e.g. #id) must start with an alphabetical letter \
or be a number (e.g. #742)"
Expand Down Expand Up @@ -3368,6 +3370,12 @@ and parse_record_expr_row p :

and parse_dict_expr_row p =
match p.Parser.token with
| DotDotDot ->
Parser.err p (Diagnostics.message ErrorMessages.dict_expr_spread);
Parser.next p;
(* Parse the expr so it's consumed *)
let _spread_expr = parse_constrained_or_coerced_expr p in
None
| String s -> (
let loc = mk_loc p.start_pos p.end_pos in
Parser.next p;
Expand Down
2 changes: 2 additions & 0 deletions tests/syntax_tests/data/parsing/errors/other/dict_spread.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let x = dict{...foo, "bar": 3}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

Syntax error!
syntax_tests/data/parsing/errors/other/dict_spread.res:1:14-16

1 │ let x = dict{...foo, "bar": 3}
2 │
3 │

Dict literals do not support spread (`...`) yet.

let x = Primitive_dict.make [|("bar", 3)|]
Loading