@@ -118,11 +118,14 @@ let protect_longident ppf print_longident longprefix txt =
118
118
let is_curry_attr attr =
119
119
attr.attr_name.txt = Builtin_attributes. curry_attr_name
120
120
121
- let filter_curry_attrs attrs =
122
- List. filter (fun attr -> not (is_curry_attr attr)) attrs
123
-
124
- let has_non_curry_attr attrs =
125
- List. exists (fun attr -> not (is_curry_attr attr)) attrs
121
+ let split_out_curry_attr attrs =
122
+ let curry, non_curry = List. partition is_curry_attr attrs in
123
+ let is_curry =
124
+ match curry with
125
+ | [] -> false
126
+ | _ :: _ -> true
127
+ in
128
+ is_curry, non_curry
126
129
127
130
type space_formatter = (unit , Format .formatter , unit ) format
128
131
@@ -496,10 +499,9 @@ and name_jkind f (name, jkind) =
496
499
(jkind_annotation reset_ctxt) jkind
497
500
498
501
and core_type ctxt f x =
499
- let filtered_attrs = filter_curry_attrs x.ptyp_attributes in
500
- if filtered_attrs <> [] then begin
502
+ if x.ptyp_attributes <> [] then begin
501
503
pp f " ((%a)%a)" (core_type ctxt) {x with ptyp_attributes= [] }
502
- (attributes ctxt) filtered_attrs
504
+ (attributes ctxt) x.ptyp_attributes
503
505
end
504
506
else match x.ptyp_desc with
505
507
| Ptyp_arrow (l , ct1 , ct2 , m1 , m2 ) ->
@@ -523,8 +525,7 @@ and core_type ctxt f x =
523
525
| _ -> pp f " @[<2>%a@]" (core_type1 ctxt) x
524
526
525
527
and core_type1 ctxt f x =
526
- (* CR zqian: the logic about curry should be pushed into Ptyp_arrow *)
527
- if has_non_curry_attr x.ptyp_attributes then core_type ctxt f x
528
+ if x.ptyp_attributes <> [] then core_type ctxt f x
528
529
else
529
530
match x.ptyp_desc with
530
531
| Ptyp_any jkind -> tyvar_loc_option_jkind f (None , jkind)
@@ -626,7 +627,9 @@ and labeled_core_type1 ctxt f (label, ty) =
626
627
core_type1 ctxt f ty
627
628
628
629
and return_type ctxt f (x , m ) =
629
- if x.ptyp_attributes <> [] then core_type_with_optional_legacy_modes core_type1 ctxt f (x, m)
630
+ let is_curry, ptyp_attributes = split_out_curry_attr x.ptyp_attributes in
631
+ let x = {x with ptyp_attributes} in
632
+ if is_curry then core_type_with_optional_legacy_modes core_type1 ctxt f (x, m)
630
633
else core_type_with_optional_legacy_modes core_type ctxt f (x, m)
631
634
632
635
and core_type_with_optional_modes ctxt f (ty , modes ) =
0 commit comments