File tree Expand file tree Collapse file tree 3 files changed +26
-15
lines changed
tests/syntax_tests/data/parsing/grammar/expressions/expected Expand file tree Collapse file tree 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)
111111 {e with pexp_desc = Pexp_constant (Pconst_integer (s, None ))}
112112 (* End rewriting *)
113113 | 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
116114 let res = self.expr self body in
117115 {e with pexp_desc = Pexp_newtype (s, res)}
118116 | 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 =
22 Ext_list. exists attrs (fun ({Location. txt} , _ ) -> txt = " res.async" )
33
44let 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
515 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)
1224 else body
1325
1426let 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 ])
3434let ex4 = (((foo.bar).baz)[@res.await ])
3535let attr1 = ((fun [arity:1]x -> x + 1)[@res.async ][@a ])
3636let 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 ])
3939let 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 ]))
4242 [@a ])
4343let 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 ]))
4646 [@a ])
4747let (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