summaryrefslogtreecommitdiff
path: root/lambda
diff options
context:
space:
mode:
authorChris Casinghino <ccasinghino@janestreet.com>2023-02-10 13:18:42 -0500
committerChris Casinghino <ccasinghino@janestreet.com>2023-02-10 13:32:29 -0500
commit3a013db64c5a1c6c6708e4ba699137329f925cde (patch)
tree6b231f89db2e9ad1633c0d62f3b31ac90d7b536f /lambda
parent61f10168da60e94a5f9c2d1ce4cc4e4d512d0007 (diff)
downloadocaml-3a013db64c5a1c6c6708e4ba699137329f925cde.tar.gz
Handle attributes on lambdas with locally abstract types
Diffstat (limited to 'lambda')
-rw-r--r--lambda/translcore.ml14
1 files changed, 13 insertions, 1 deletions
diff --git a/lambda/translcore.ml b/lambda/translcore.ml
index 879668eed3..0c95110779 100644
--- a/lambda/translcore.ml
+++ b/lambda/translcore.ml
@@ -875,7 +875,19 @@ and transl_function ~scopes e param cases partial =
let attr = default_function_attribute in
let loc = of_location ~scopes e.exp_loc in
let lam = lfunction ~kind ~params ~return ~body ~attr ~loc in
- Translattribute.add_function_attributes lam e.exp_loc e.exp_attributes
+ let attrs =
+ (* Collect attributes from the Pexp_newtype node for locally abstract types.
+ Otherwise we'd ignore the attribute in, e.g.:
+ fun [@inline] (type a) x -> ...
+ *)
+ List.fold_left
+ (fun attrs (extra_exp, _, extra_attrs) ->
+ match extra_exp with
+ | Texp_newtype _ -> extra_attrs @ attrs
+ | (Texp_constraint _ | Texp_coerce _ | Texp_poly _) -> attrs)
+ e.exp_attributes e.exp_extra
+ in
+ Translattribute.add_function_attributes lam e.exp_loc attrs
(* Like transl_exp, but used when a new scope was just introduced. *)
and transl_scoped_exp ~scopes expr =