Skip to content

Commit a408496

Browse files
committed
Merge branch 'MAIN' into 53_compat
2 parents e17b2ec + 864d6a5 commit a408496

File tree

10 files changed

+33
-22
lines changed

10 files changed

+33
-22
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ profile. This started with version 0.26.0.
6161
- \* Fix arrow type indentation with `break-separators=before` (#2598, @Julow)
6262
- Fix formatting of short `fun` expressions with the janestreet profile (#2593, @Julow)
6363
- Fix missing parentheses around a let in class expressions (#2599, @Julow)
64+
- Fix dropped attribute in `(module M : S [@attr])` (#2602, @Julow)
6465
- Build on OCaml 5.3 (#2603, @adamchol, @Julow)
6566

6667
### Changes

lib/Ast.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ end = struct
968968
| {prf_desc= Rtag (_, _, t1N); _} -> List.exists t1N ~f
969969
| {prf_desc= Rinherit t1; _} -> typ == t1 ) )
970970
| Ptyp_open (_, t1) -> assert (t1 == typ)
971-
| Ptyp_package (_, it1N) -> assert (List.exists it1N ~f:snd_f)
971+
| Ptyp_package (_, it1N, _) -> assert (List.exists it1N ~f:snd_f)
972972
| Ptyp_object (fields, _) ->
973973
assert (
974974
List.exists fields ~f:(function
@@ -1001,14 +1001,14 @@ end = struct
10011001
match ctx.ppat_desc with
10021002
| Ppat_constraint (_, t1) -> assert (typ == t1)
10031003
| Ppat_extension (_, PTyp t) -> assert (typ == t)
1004-
| Ppat_unpack (_, Some (_, l)) ->
1004+
| Ppat_unpack (_, Some (_, l, _)) ->
10051005
assert (List.exists l ~f:(fun (_, t) -> typ == t))
10061006
| Ppat_record (l, _) ->
10071007
assert (List.exists l ~f:(fun (_, t, _) -> Option.exists t ~f))
10081008
| _ -> assert false )
10091009
| Exp ctx -> (
10101010
match ctx.pexp_desc with
1011-
| Pexp_pack (_, Some (_, it1N)) -> assert (List.exists it1N ~f:snd_f)
1011+
| Pexp_pack (_, Some (_, it1N, _)) -> assert (List.exists it1N ~f:snd_f)
10121012
| Pexp_constraint (_, t1)
10131013
|Pexp_coerce (_, None, t1)
10141014
|Pexp_extension (_, PTyp t1) ->
@@ -1046,7 +1046,7 @@ end = struct
10461046
| Mod ctx -> (
10471047
match ctx.pmod_desc with
10481048
| Pmod_unpack (_, ty1, ty2) ->
1049-
let f (_, cstrs) = List.exists cstrs ~f:(fun (_, x) -> f x) in
1049+
let f (_, cstrs, _) = List.exists cstrs ~f:(fun (_, x) -> f x) in
10501050
assert (Option.exists ty1 ~f || Option.exists ty2 ~f)
10511051
| _ -> assert false )
10521052
| Sig ctx -> (

lib/Fmt_ast.ml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -909,10 +909,11 @@ and fmt_core_type c ?(box = true) ?pro ?(pro_space = true) ?constraint_ctx
909909
$ space_break $ fmt_longident_loc c lid )
910910
| Ptyp_extension ext ->
911911
hvbox c.conf.fmt_opts.extension_indent.v (fmt_extension c ctx ext)
912-
| Ptyp_package (id, cnstrs) ->
912+
| Ptyp_package (id, cnstrs, attrs) ->
913913
hvbox 2
914914
( hovbox 0 (str "module" $ space_break $ fmt_longident_loc c id)
915-
$ fmt_package_type c ctx cnstrs )
915+
$ fmt_package_type c ctx cnstrs
916+
$ fmt_attributes c attrs )
916917
| Ptyp_open (lid, typ) ->
917918
hvbox 2
918919
( hvbox 0 (fmt_longident_loc c lid $ str ".(")
@@ -1293,13 +1294,14 @@ and fmt_pattern ?ext c ?pro ?parens ?(box = false)
12931294
| Ppat_unpack (name, pt) ->
12941295
let fmt_constraint_opt pt k =
12951296
match pt with
1296-
| Some (id, cnstrs) ->
1297+
| Some (id, cnstrs, attrs) ->
12971298
hovbox 0
12981299
(Params.parens_if parens c.conf
12991300
(hvbox 1
13001301
( hovbox 0
13011302
(k $ space_break $ str ": " $ fmt_longident_loc c id)
1302-
$ fmt_package_type c ctx cnstrs ) ) )
1303+
$ fmt_package_type c ctx cnstrs
1304+
$ fmt_attributes c attrs ) ) )
13031305
| None -> wrap_fits_breaks_if ~space:false c.conf parens "(" ")" k
13041306
in
13051307
fmt_constraint_opt pt
@@ -2594,10 +2596,11 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens
25942596
and epi = cls_paren in
25952597
let fmt_mod m =
25962598
match pt with
2597-
| Some (id, cnstrs) ->
2599+
| Some (id, cnstrs, attrs) ->
25982600
hvbox 2
25992601
( hovbox 0 (m $ space_break $ str ": " $ fmt_longident_loc c id)
2600-
$ fmt_package_type c ctx cnstrs )
2602+
$ fmt_package_type c ctx cnstrs
2603+
$ fmt_attributes c attrs )
26012604
| None -> m
26022605
in
26032606
outer_pro
@@ -4330,11 +4333,12 @@ and fmt_module_expr ?(dock_struct = true) c ({ast= m; _} as xmod) =
43304333
(str "end" $ fmt_attributes_and_docstrings c pmod_attributes)
43314334
$ after ) }
43324335
| Pmod_unpack (e, ty1, ty2) ->
4333-
let package_type sep (lid, cstrs) =
4336+
let package_type sep (lid, cstrs, attrs) =
43344337
break 1 (Params.Indent.mod_unpack_annot c.conf)
43354338
$ hovbox 0
43364339
( hovbox 0 (str sep $ fmt_longident_loc c lid)
4337-
$ fmt_package_type c ctx cstrs )
4340+
$ fmt_package_type c ctx cstrs
4341+
$ fmt_attributes c attrs )
43384342
in
43394343
{ empty with
43404344
opn= Some (open_hvbox 2)

test/passing/tests/first_class_module.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,5 @@ let x = (module M : S)
114114

115115
(* Unpack containing a [pexp_constraint]. *)
116116
module T = (val (x : (module S)))
117+
118+
let _ = (module Int : T [@foo])

test/passing/tests/first_class_module.ml.ref

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,5 @@ let x = (module M : S)
116116

117117
(* Unpack containing a [pexp_constraint]. *)
118118
module T = (val (x : (module S)))
119+
120+
let _ = (module Int : T[@foo])

vendor/parser-extended/ast_helper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module Typ = struct
8080
let alias ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_alias (a, b))
8181
let variant ?loc ?attrs a b c = mk ?loc ?attrs (Ptyp_variant (a, b, c))
8282
let poly ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_poly (a, b))
83-
let package ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_package (a, b))
83+
let package ?loc ?attrs p = mk ?loc ?attrs (Ptyp_package p)
8484
let extension ?loc ?attrs a = mk ?loc ?attrs (Ptyp_extension a)
8585
let open_ ?loc ?attrs mod_ident t = mk ?loc ?attrs (Ptyp_open (mod_ident, t))
8686
end

vendor/parser-extended/ast_mapper.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ let map_loc sub {loc; txt} = {loc = sub.location sub loc; txt}
9696
let variant_var sub x =
9797
{loc = sub.location sub x.loc; txt= map_loc sub x.txt}
9898

99-
let map_package_type sub (lid, l) =
100-
(map_loc sub lid), (List.map (map_tuple (map_loc sub) (sub.typ sub)) l)
99+
let map_package_type sub (lid, l, attrs) =
100+
(map_loc sub lid),
101+
(List.map (map_tuple (map_loc sub) (sub.typ sub)) l),
102+
sub.attributes sub attrs
101103

102104
let map_arg_label sub = function
103105
| Asttypes.Nolabel -> Asttypes.Nolabel
@@ -240,8 +242,7 @@ module T = struct
240242
| Ptyp_poly (sl, t) -> poly ~loc ~attrs
241243
(List.map (map_loc sub) sl) (sub.typ sub t)
242244
| Ptyp_package pt ->
243-
let lid, l = map_package_type sub pt in
244-
package ~loc ~attrs lid l
245+
package ~loc ~attrs (map_package_type sub pt)
245246
| Ptyp_open (mod_ident, t) ->
246247
open_ ~loc ~attrs (map_loc sub mod_ident) (sub.typ sub t)
247248
| Ptyp_extension x -> extension ~loc ~attrs (sub.extension sub x)

vendor/parser-extended/parser.mly

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,12 +3612,11 @@ atomic_type:
36123612

36133613
%inline package_core_type: module_type
36143614
{ let (lid, cstrs, attrs) = package_type_of_module_type $1 in
3615-
let descr = Ptyp_package (lid, cstrs) in
3615+
let descr = Ptyp_package (lid, cstrs, []) in
36163616
mktyp ~loc:$sloc ~attrs descr }
36173617
;
36183618
%inline package_type: module_type
3619-
{ let (lid, cstrs, _attrs) = package_type_of_module_type $1 in
3620-
(lid, cstrs) }
3619+
{ package_type_of_module_type $1 }
36213620
;
36223621
%inline row_field_list:
36233622
separated_nonempty_llist(BAR, row_field)

vendor/parser-extended/parsetree.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ and core_type_desc =
181181
| Ptyp_open of Longident.t loc * core_type (** [M.(T)] *)
182182
| Ptyp_extension of extension (** [[%id]]. *)
183183

184-
and package_type = Longident.t loc * (Longident.t loc * core_type) list
184+
and package_type =
185+
Longident.t loc * (Longident.t loc * core_type) list * attributes
185186
(** As {!package_type} typed values:
186187
- [(S, [])] represents [(module S)],
187188
- [(S, [(t1, T1) ; ... ; (tn, Tn)])]

vendor/parser-extended/printast.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ and package_with i ppf (s, t) =
259259
line i ppf "with type %a\n" fmt_longident_loc s;
260260
core_type i ppf t
261261

262-
and package_type i ppf (s, l) =
262+
and package_type i ppf (s, l, attrs) =
263263
line i ppf "package_type %a\n" fmt_longident_loc s;
264+
attributes (i+1) ppf attrs;
264265
list i package_with ppf l
265266

266267
and pattern i ppf x =

0 commit comments

Comments
 (0)