Skip to content

Commit 2423ad0

Browse files
committed
Fix arity of inner functions.
The parser gives arity to inner functions while it should only give it to the toplevel for a nested function. E.g. (x,y) => x+y should give toplevel arity 2, and no inner arity 1
1 parent 3ca735a commit 2423ad0

29 files changed

+149
-193
lines changed

compiler/syntax/src/res_core.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,8 +1596,8 @@ and parse_es6_arrow_expression ?(arrow_attrs = []) ?(arrow_start_pos = None)
15961596
{attrs; label = lbl; expr = default_expr; pat; pos = start_pos} ->
15971597
let loc = mk_loc start_pos end_pos in
15981598
let fun_expr =
1599-
Ast_helper.Exp.fun_ ~loc ~attrs ~arity:(Some arity) lbl default_expr
1600-
pat expr
1599+
Ast_helper.Exp.fun_ ~loc ~attrs ~arity:None lbl default_expr pat
1600+
expr
16011601
in
16021602
if term_param_num = 1 then
16031603
( term_param_num - 1,

tests/syntax_tests/data/parsing/errors/expressions/expected/arrow.res.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@
1111
;;(Object.keys providers).reduce
1212
(Function$
1313
(fun [arity:2]elements ->
14-
fun [arity:1]providerId -> ((let x = 1 in let b = 2 in x + b)
15-
[@res.braces ])))
14+
fun providerId -> ((let x = 1 in let b = 2 in x + b)[@res.braces ])))

tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@
6666
let findThreadByIdLinearScan =
6767
Function$
6868
(fun [arity:2]~threads:((threads)[@res.namedArgLoc ]) ->
69-
fun [arity:1]~id:((id)[@res.namedArgLoc ]) ->
69+
fun ~id:((id)[@res.namedArgLoc ]) ->
7070
((Js.Array2.findi ThreadsModel.threads
7171
(Function$
7272
(fun [arity:2]thread ->
73-
fun [arity:1]i ->
73+
fun i ->
7474
((let thisId =
7575
match thread with
7676
| ServerData.OneToOne

tests/syntax_tests/data/parsing/errors/expressions/expected/consecutive.res.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@
4444

4545
consecutive expressions on a line must be separated by ';' or a newline
4646

47-
let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> a + 3)
47+
let f = Function$ (fun [arity:2]a -> fun b -> a + 3)
4848
;;b
49-
let f =
50-
Function$ (fun [arity:2]g -> fun [arity:1]h -> ((a + 3; b)[@res.braces ]))
49+
let f = Function$ (fun [arity:2]g -> fun h -> ((a + 3; b)[@res.braces ]))
5150
let () = ((sideEffect1 (); sideEffect2 ())[@res.braces ])
5251
let () = ((let open Foo in let exception End in x ())[@res.braces ])
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
let x = { }
2-
let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> { })
2+
let f = Function$ (fun [arity:2]a -> fun b -> { })

tests/syntax_tests/data/parsing/errors/other/expected/labelledParameters.res.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@
3131

3232
A labeled parameter starts with a `~`. Did you mean: `~x`?
3333

34-
let f =
35-
Function$
36-
(fun [arity:3]x -> fun [arity:2]?(y= 2) -> fun [arity:1]z -> (x + y) + z)
34+
let f = Function$ (fun [arity:3]x -> fun ?(y= 2) -> fun z -> (x + y) + z)
3735
let g =
3836
Function$
3937
(fun [arity:3]~x:((x)[@res.namedArgLoc ]) ->
40-
fun [arity:2]?y:(((y)[@res.namedArgLoc ])= 2) ->
41-
fun [arity:1]~z:((z)[@res.namedArgLoc ]) -> (x + y) + z)
38+
fun ?y:(((y)[@res.namedArgLoc ])= 2) ->
39+
fun ~z:((z)[@res.namedArgLoc ]) -> (x + y) + z)
4240
type nonrec f = (x:int -> y:int -> int, [ `Has_arity2 ]) function$

tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module ClientSet =
3535
let cmp =
3636
Function$
3737
(fun [arity:2]a ->
38-
fun [arity:1]b ->
38+
fun b ->
3939
((compare
4040
(a |.u Client.getUniqueId)
4141
(b |.u Client.getUniqueId))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[@@@uncurried ]
2-
let foo = Function$ (fun [arity:2]x -> fun [arity:1]y -> x + y)
2+
let foo = Function$ (fun [arity:2]x -> fun y -> x + y)
33
let z = foo 3 4
4-
let bar = Function$ (fun [arity:2]x -> fun [arity:1]y -> x + y)
4+
let bar = Function$ (fun [arity:2]x -> fun y -> x + y)
55
let b = bar 3 4
66
let w = 3 |.u (foo 4)
77
let a = 3 |.u (foo 4)

tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ let uFun = Function$ (fun [arity:1]x -> 3)
55
let mixFun =
66
Function$
77
(fun [arity:3]a ->
8-
fun [arity:2]b ->
9-
fun [arity:1]c ->
8+
fun b ->
9+
fun c ->
1010
Function$
1111
(fun [arity:3]d ->
12-
fun [arity:2]e ->
13-
fun [arity:1]f ->
14-
Function$ (fun [arity:2]g -> fun [arity:1]h -> 4)))
12+
fun e -> fun f -> Function$ (fun [arity:2]g -> fun h -> 4)))
1513
let bracesFun =
1614
Function$ (fun [arity:1]x -> Function$ (fun [arity:1]y -> x + y))
17-
let cFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3)
18-
let uFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3)
15+
let cFun2 = Function$ (fun [arity:2]x -> fun y -> 3)
16+
let uFun2 = Function$ (fun [arity:2]x -> fun y -> 3)
1917
type nonrec cTyp = (string -> int, [ `Has_arity1 ]) function$
2018
type nonrec uTyp = (string -> int, [ `Has_arity1 ]) function$
2119
type nonrec mixTyp =
@@ -77,19 +75,19 @@ let _ = Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ])
7775
let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@att ]))
7876
let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ]))
7977
let t0 (type a) (type b) =
80-
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
78+
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
8179
let t1 (type a) (type b) =
82-
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
80+
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
8381
let t2 (type a) (type b) =
84-
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
82+
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
8583
let t3 (type a) (type b) =
86-
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
84+
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
8785
let t4 (type a) (type b) =
88-
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
86+
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
8987
let t5 (type a) (type b) =
90-
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
88+
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
9189
let t6 (type a) (type b) =
92-
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
90+
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
9391
type nonrec arrowPath1 = (int -> string, [ `Has_arity1 ]) function$
9492
type nonrec arrowPath2 = (I.t -> string, [ `Has_arity1 ]) function$
9593
type nonrec arrowPath3 = (int -> string, [ `Has_arity1 ]) function$
@@ -109,18 +107,18 @@ let mixFun =
109107
(fun [arity:1]a ->
110108
Function$
111109
(fun [arity:2]b ->
112-
fun [arity:1]c ->
110+
fun c ->
113111
Function$
114112
(fun [arity:3]d ->
115-
fun [arity:2]e ->
116-
fun [arity:1]f ->
113+
fun e ->
114+
fun f ->
117115
Function$
118116
(fun [arity:1]g -> Function$ (fun [arity:1]h -> 4)))))
119117
let bracesFun =
120118
Function$ (fun [arity:1]x -> Function$ (fun [arity:1]y -> x + y))
121-
let cFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3)
122-
let uFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3)
123-
let cFun2Dots = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3)
119+
let cFun2 = Function$ (fun [arity:2]x -> fun y -> 3)
120+
let uFun2 = Function$ (fun [arity:2]x -> fun y -> 3)
121+
let cFun2Dots = Function$ (fun [arity:2]x -> fun y -> 3)
124122
type nonrec cTyp = (string -> int, [ `Has_arity1 ]) function$
125123
type nonrec uTyp = (string -> int, [ `Has_arity1 ]) function$
126124
type nonrec mixTyp =
@@ -184,13 +182,13 @@ let _ = Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ])
184182
let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@att ]))
185183
let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ]))
186184
let t0 (type a) (type b) =
187-
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
185+
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
188186
let t1 (type a) (type b) =
189-
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
187+
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
190188
let t2 (type a) (type b) =
191-
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
189+
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
192190
let t3 (type a) (type b) =
193-
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
191+
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
194192
type nonrec arrowPath1 = (int -> string, [ `Has_arity1 ]) function$
195193
type nonrec arrowPath2 = (I.t -> string, [ `Has_arity1 ]) function$
196194
type nonrec arrowPath3 = (int -> string, [ `Has_arity1 ]) function$

tests/syntax_tests/data/parsing/grammar/expressions/expected/apply.res.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
;;foo (Function$ (fun [arity:1]_ -> bla))
55
(Function$ (fun [arity:1]_ -> blaz))
66
;;List.map (Function$ (fun [arity:1]x -> x + 1)) myList
7-
;;List.reduce
8-
(Function$ (fun [arity:2]acc -> fun [arity:1]curr -> acc + curr)) 0
7+
;;List.reduce (Function$ (fun [arity:2]acc -> fun curr -> acc + curr)) 0
98
myList
109
let unitUncurried = apply ()
1110
;;call ~a:(((((a)[@res.namedArgLoc ]) : int))[@res.namedArgLoc ])

0 commit comments

Comments
 (0)