File tree 3 files changed +26
-15
lines changed
tests/syntax_tests/data/parsing/grammar/expressions/expected
3 files changed +26
-15
lines changed Original file line number Diff line number Diff line change @@ -111,8 +111,6 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
111
111
{e with pexp_desc = Pexp_constant (Pconst_integer (s, None ))}
112
112
(* End rewriting *)
113
113
| Pexp_newtype (s , body ) ->
114
- let async = Ast_async. has_async_payload e.pexp_attributes in
115
- let body = Ast_async. add_async_attribute ~async body in
116
114
let res = self.expr self body in
117
115
{e with pexp_desc = Pexp_newtype (s, res)}
118
116
| Pexp_fun {arg_label = label ; lhs = pat ; rhs = body } -> (
Original file line number Diff line number Diff line change @@ -2,13 +2,25 @@ let has_async_payload attrs =
2
2
Ext_list. exists attrs (fun ({Location. txt} , _ ) -> txt = " res.async" )
3
3
4
4
let add_async_attribute ~async (body : Parsetree.expression ) =
5
+ let add (exp : Parsetree.expression ) =
6
+ if has_async_payload exp.pexp_attributes then exp
7
+ else
8
+ {
9
+ exp with
10
+ pexp_attributes =
11
+ ({txt = " res.async" ; loc = Location. none}, PStr [] )
12
+ :: exp.pexp_attributes;
13
+ }
14
+ in
5
15
if async then
6
- {
7
- body with
8
- pexp_attributes =
9
- ({txt = " res.async" ; loc = Location. none}, PStr [] )
10
- :: body.pexp_attributes;
11
- }
16
+ let rec add_to_fun (exp : Parsetree.expression ) =
17
+ match exp.pexp_desc with
18
+ | Pexp_newtype (txt , e ) ->
19
+ {exp with pexp_desc = Pexp_newtype (txt, add_to_fun e)}
20
+ | Pexp_fun _ -> add exp
21
+ | _ -> exp
22
+ in
23
+ add (add_to_fun body)
12
24
else body
13
25
14
26
let add_promise_type ?(loc = Location. none) ~async
Original file line number Diff line number Diff line change @@ -34,15 +34,16 @@ let ex3 = ((foo |.u (bar ~arg:((arg)[@res.namedArgLoc ])))[@res.await ])
34
34
let ex4 = (((foo.bar).baz)[@res.await ])
35
35
let attr1 = ((fun [arity:1]x -> x + 1)[@res.async ][@a ])
36
36
let attr2 = ((fun (type a) ->
37
- fun [arity:1]() -> fun (type b) -> fun (type c) -> fun [arity:1]x -> 3)
38
- [@res.async ][@a ])
37
+ (( fun [arity:1]() -> fun (type b) -> fun (type c) -> fun [arity:1]x -> 3)
38
+ [@res.async ]))[@res.async ] [@a ])
39
39
let attr3 = ((fun (type a) ->
40
- fun [arity:1]() -> ((fun (type b) -> fun (type c) -> fun [arity:1]x -> 3)
41
- [@res.async ]))
40
+ fun [arity:1]() -> ((fun (type b) -> fun (type c) -> (( fun [arity:1]x -> 3)
41
+ [@res.async ]))[@res.async ]))
42
42
[@a ])
43
43
let attr4 = ((fun (type a) ->
44
- fun [arity:1]() -> ((fun (type b) -> fun (type c) -> fun [arity:1]x -> 3)
45
- [@res.async ][@b ]))
44
+ fun [arity:1]() -> ((fun (type b) -> fun (type c) -> (( fun [arity:1]x -> 3)
45
+ [@res.async ]))[@res.async ] [@b ]))
46
46
[@a ])
47
47
let (attr5 : int) = ((fun (type a) -> fun (type b) -> fun (type c) ->
48
- fun [arity:1]() -> fun [arity:1](x : a) -> x)[@res.async ][@a ][@b ])
48
+ ((fun [arity:1]() -> fun [arity:1](x : a) -> x)[@res.async ]))
49
+ [@res.async ][@a ][@b ])
You can’t perform that action at this time.
0 commit comments