From c41e56fa808f6ef703daee0700f7ec0b40c1a734 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 18 Sep 2025 16:45:55 +0200 Subject: [PATCH 1/2] dedicated error for dict literal spread --- compiler/syntax/src/res_core.ml | 7 +++++++ .../data/parsing/errors/other/dict_spread.res | 2 ++ .../parsing/errors/other/expected/dict_spread.res.txt | 11 +++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/syntax_tests/data/parsing/errors/other/dict_spread.res create mode 100644 tests/syntax_tests/data/parsing/errors/other/expected/dict_spread.res.txt diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index 380fe21c2e..b27c4eff55 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,11 @@ 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; + 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..c8e0863b46 --- /dev/null +++ b/tests/syntax_tests/data/parsing/errors/other/dict_spread.res @@ -0,0 +1,2 @@ +let x = dict{...foo} + 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..4aea43ae4c --- /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} + 2 │ + 3 │ + + Dict literals do not support spread (`...`) yet. + +let x = Primitive_dict.make [||] \ No newline at end of file From 30c85627d31b35231531bf9bc76cfe87e0c95b58 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 18 Sep 2025 16:48:47 +0200 Subject: [PATCH 2/2] fix and changelog --- CHANGELOG.md | 1 + compiler/syntax/src/res_core.ml | 1 + tests/syntax_tests/data/parsing/errors/other/dict_spread.res | 2 +- .../data/parsing/errors/other/expected/dict_spread.res.txt | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) 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 b27c4eff55..08889c8ce3 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -3373,6 +3373,7 @@ and parse_dict_expr_row p = | 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 -> ( diff --git a/tests/syntax_tests/data/parsing/errors/other/dict_spread.res b/tests/syntax_tests/data/parsing/errors/other/dict_spread.res index c8e0863b46..2bdc394557 100644 --- a/tests/syntax_tests/data/parsing/errors/other/dict_spread.res +++ b/tests/syntax_tests/data/parsing/errors/other/dict_spread.res @@ -1,2 +1,2 @@ -let x = dict{...foo} +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 index 4aea43ae4c..5c5856aeb3 100644 --- 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 @@ -2,10 +2,10 @@ Syntax error! syntax_tests/data/parsing/errors/other/dict_spread.res:1:14-16 - 1 │ let x = dict{...foo} + 1 │ let x = dict{...foo, "bar": 3} 2 │ 3 │ Dict literals do not support spread (`...`) yet. -let x = Primitive_dict.make [||] \ No newline at end of file +let x = Primitive_dict.make [|("bar", 3)|] \ No newline at end of file