Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ profile. This started with version 0.26.0.

- Fix a crash on `type 'a t = A : 'a. {a: 'a} -> 'a t`. (#2710, @EmileTrotignon)

- Fix a crash where `type%e nonrec t = t` was formatted as `type nonrec%e t = t`,
which is invalid syntax. (#2712, @EmileTrotignon)

### Changed

- `|> begin`, `~arg:begin`, `begin if`, `lazy begin`, `begin match`,
Expand Down
19 changes: 11 additions & 8 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3457,7 +3457,8 @@ and fmt_class_params c ctx params =
( wrap_fits_breaks c.conf "[" "]" (list_fl params fmt_param)
$ space_break ) )

and fmt_type_declaration c ?(pre = "") ?name ?(eq = "=") {ast= decl; _} =
and fmt_type_declaration c ?(kw = "") ?(nonrec_kw = "") ?name ?(eq = "=")
{ast= decl; _} =
protect c (Td decl)
@@
let { ptype_name= {txt; loc}
Expand Down Expand Up @@ -3497,10 +3498,10 @@ and fmt_type_declaration c ?(pre = "") ?name ?(eq = "=") {ast= decl; _} =
in
let box_manifest k =
hvbox c.conf.fmt_opts.type_decl_indent.v
( str pre
( str kw
$ fmt_extension_suffix c ext
$ fmt_attributes c attrs_before
$ str " "
$ str nonrec_kw $ str " "
$ hvbox_if
(not (List.is_empty ptype_params))
0
Expand Down Expand Up @@ -4265,12 +4266,12 @@ and fmt_module_statement c ~attributes ?keyword mod_expr =

and fmt_with_constraint c ctx ~pre = function
| Pwith_type (lid, td) ->
fmt_type_declaration ~pre:(pre ^ " type") c ~name:lid (sub_td ~ctx td)
fmt_type_declaration ~kw:(pre ^ " type") c ~name:lid (sub_td ~ctx td)
| Pwith_module (m1, m2) ->
str pre $ str " module " $ fmt_longident_loc c m1 $ str " = "
$ fmt_longident_loc c m2
| Pwith_typesubst (lid, td) ->
fmt_type_declaration ~pre:(pre ^ " type") c ~eq:":=" ~name:lid
fmt_type_declaration ~kw:(pre ^ " type") c ~eq:":=" ~name:lid
(sub_td ~ctx td)
| Pwith_modsubst (m1, m2) ->
str pre $ str " module " $ fmt_longident_loc c m1 $ str " := "
Expand Down Expand Up @@ -4550,10 +4551,12 @@ and fmt_type c ?eq rec_flag decls ctx =
let is_rec = Asttypes.is_recursive rec_flag in
let fmt_decl c ctx ~prev ~next:_ decl =
let first = Option.is_none prev in
let pre =
if first then if is_rec then "type" else "type nonrec" else "and"
let kw, nonrec_kw =
if first then
if is_rec then ("type", None) else ("type", Some " nonrec")
else ("and", None)
in
fmt_type_declaration c ~pre ?eq (sub_td ~ctx decl)
fmt_type_declaration c ~kw ?nonrec_kw ?eq (sub_td ~ctx decl)
in
let ast x = Td x in
fmt_item_list c ctx update_config ast fmt_decl decls
Expand Down
4 changes: 4 additions & 0 deletions test/passing/refs.ahrefs/extensions-indent.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,7 @@ let xxxxxx =
yyyyyyyy
in
{ zzzzzzzzzzzzz }

type%e nonrec t = t

type%e[@a] nonrec t = t
4 changes: 4 additions & 0 deletions test/passing/refs.ahrefs/extensions.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -551,3 +551,7 @@ let xxxxxx =
yyyyyyyy
in
{ zzzzzzzzzzzzz }

type%e nonrec t = t

type%e[@a] nonrec t = t
3 changes: 3 additions & 0 deletions test/passing/refs.default/extensions-indent.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,6 @@ let xxxxxx =
yyyyyyyy
in
{ zzzzzzzzzzzzz }

type%e nonrec t = t
type%e[@a] nonrec t = t
3 changes: 3 additions & 0 deletions test/passing/refs.default/extensions.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,6 @@ let xxxxxx =
yyyyyyyy
in
{ zzzzzzzzzzzzz }

type%e nonrec t = t
type%e[@a] nonrec t = t
3 changes: 3 additions & 0 deletions test/passing/refs.janestreet/extensions-indent.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -697,3 +697,6 @@ let xxxxxx =
__________ *) () = yyyyyyyy in
{ zzzzzzzzzzzzz }
;;

type%e nonrec t = t
type%e[@a] nonrec t = t
3 changes: 3 additions & 0 deletions test/passing/refs.janestreet/extensions.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -697,3 +697,6 @@ let xxxxxx =
__________ *) () = yyyyyyyy in
{ zzzzzzzzzzzzz }
;;

type%e nonrec t = t
type%e[@a] nonrec t = t
4 changes: 4 additions & 0 deletions test/passing/refs.ocamlformat/extensions-indent.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,7 @@ let xxxxxx =
yyyyyyyy
in
{zzzzzzzzzzzzz}

type%e nonrec t = t

type%e[@a] nonrec t = t
4 changes: 4 additions & 0 deletions test/passing/refs.ocamlformat/extensions.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,7 @@ let xxxxxx =
yyyyyyyy
in
{zzzzzzzzzzzzz}

type%e nonrec t = t

type%e[@a] nonrec t = t
4 changes: 4 additions & 0 deletions test/passing/tests/extensions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,7 @@ let xxxxxx =
let%map (* _____________________________
__________ *)() = yyyyyyyy in
{ zzzzzzzzzzzzz }

type%e nonrec t = t

type%e [@a] nonrec t = t
Loading