Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 3f77897

Browse files
concat accept an array; tests update
1 parent 0447df1 commit 3f77897

File tree

4 files changed

+6
-16
lines changed

4 files changed

+6
-16
lines changed

src/res_core.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3753,7 +3753,7 @@ and parseListExpr ~startPos p =
37533753
Ast_helper.Exp.(apply ~loc
37543754
(Ast_helper.Exp.ident ~loc
37553755
(Location.mkloc (Longident.(Ldot (Ldot (Lident "Belt", "List"), "concatMany"))) loc))
3756-
[Asttypes.Nolabel, makeListExpression loc listExprs None])
3756+
[Asttypes.Nolabel, Ast_helper.Exp.array ~loc listExprs])
37573757
(* | (true (\* spread expression *\), expr, _) :: exprs ->
37583758
* let exprs = check_all_non_spread_exp exprs in
37593759
* makeListExpression loc exprs (Some expr)

tests/parsing/errors/other/expected/spread.res.txt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,6 @@ Explanation: you can't collect a subset of a record's field into its own record,
4949
Solution: you need to pull out each field you want explicitly.
5050

5151

52-
Syntax error!
53-
tests/parsing/errors/other/spread.res:8:1-3
54-
55-
6 │
56-
7 │ let myList = list{...x, ...y}
57-
8 │ let list{...x, ...y} = myList
58-
9 │
59-
10 │ type t = {...a}
60-
61-
Lists can only have one `...` spread, and at the end.
62-
Explanation: lists are singly-linked list, where a node contains a value and points to the next node. `list{a, ...bc}` efficiently creates a new item and links `bc` as its next nodes. `list{...bc, a}` would be expensive, as it'd need to traverse `bc` and prepend each item to `a` one by one. We therefore disallow such syntax sugar.
63-
Solution: directly use `concat`.
64-
65-
6652
Syntax error!
6753
tests/parsing/errors/other/spread.res:8:13-22
6854

@@ -114,7 +100,7 @@ let arr = [|x;y|]
114100
let [|arr;_|] = [|1;2;3|]
115101
let record = { x with y }
116102
let { x; y } = myRecord
117-
let myList = x :: y
103+
let myList = Belt.List.concatMany [|x;y|]
118104
let x::y = myList
119105
type nonrec t = < a >
120106
type nonrec t =

tests/parsing/grammar/expressions/expected/list.res.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ let x = [1; 2; 3]
33
let x = [1; 2; 3]
44
let x = [(1 : int); (2 : int); (3 : int)]
55
let x = 4 :: 5 :: y
6+
let x = Belt.List.concatMany [|(1 :: x);(2 :: 3 :: x)|]
67
let x = 1 :: 2 :: (y : int list)

tests/parsing/grammar/expressions/list.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ let x = list{1: int, (2: int), 3: int}
1212
// spread
1313
let x = list{4, 5, ...y}
1414

15+
// spread anywhere
16+
let x = list{1, ...x, 2, 3, ...x}
17+
1518
// spread constrained expression
1619
let x = list{1, 2, ...y: list<int>}

0 commit comments

Comments
 (0)