diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b020f7241..41acaf240a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index 380fe21c2e..08889c8ce3 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -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." + let variant_ident = "A polymorphic variant (e.g. #id) must start with an alphabetical letter \ or be a number (e.g. #742)" @@ -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; diff --git a/tests/syntax_tests/data/parsing/errors/other/dict_spread.res b/tests/syntax_tests/data/parsing/errors/other/dict_spread.res new file mode 100644 index 0000000000..2bdc394557 --- /dev/null +++ b/tests/syntax_tests/data/parsing/errors/other/dict_spread.res @@ -0,0 +1,2 @@ +let x = dict{...foo, "bar": 3} + diff --git a/tests/syntax_tests/data/parsing/errors/other/expected/dict_spread.res.txt b/tests/syntax_tests/data/parsing/errors/other/expected/dict_spread.res.txt new file mode 100644 index 0000000000..5c5856aeb3 --- /dev/null +++ b/tests/syntax_tests/data/parsing/errors/other/expected/dict_spread.res.txt @@ -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)|] \ No newline at end of file