Skip to content

Commit 169c480

Browse files
Fixes a bug in class type when trying to disable ocamlformat (#2525)
1 parent 8c20da8 commit 169c480

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ profile. This started with version 0.26.0.
4444
- Fix position of comments around and within `(type ...)` function arguments (#2503, @gpetiot)
4545
- Fix missing parentheses around constraint expressions with attributes (#2513, @alanechang)
4646
- Fix formatting of type vars in GADT constructors (#2518, @Julow)
47+
- Fix `[@ocamlformat "disable"]` inside `class type` constructs. (#2525, @EmileTrotignon)
4748

4849
## 0.26.1 (2023-09-15)
4950

lib/Fmt_ast.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ let update_config_maybe_disabled c loc l f =
178178
let c = update_config c l in
179179
maybe_disabled c loc l f
180180

181+
let update_config_maybe_disabled_k c loc l ~if_disabled enabled =
182+
let c = update_config c l in
183+
maybe_disabled_k c loc l enabled if_disabled
184+
181185
let update_config_maybe_disabled_attrs c loc attrs f =
182186
let l = attrs.attrs_before @ attrs.attrs_after in
183187
update_config_maybe_disabled c loc l f
@@ -2874,7 +2878,8 @@ and fmt_class_type ?(pro = noop) c ({ast= typ; _} as xtyp) =
28742878
protect c (Cty typ)
28752879
@@
28762880
let {pcty_desc; pcty_loc; pcty_attributes} = typ in
2877-
update_config_maybe_disabled c pcty_loc pcty_attributes
2881+
update_config_maybe_disabled_k c pcty_loc pcty_attributes
2882+
~if_disabled:(fun fmt -> vbox 2 (pro $ fmt) )
28782883
@@ fun c ->
28792884
let doc, atrs = doc_atrs pcty_attributes in
28802885
let parens = parenze_cty xtyp in

test/passing/dune.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,24 @@
13281328
(package ocamlformat)
13291329
(action (diff tests/disable_attr.ml.err disable_attr.ml.stderr)))
13301330

1331+
(rule
1332+
(deps tests/.ocamlformat )
1333+
(package ocamlformat)
1334+
(action
1335+
(with-stdout-to disable_class_type.ml.stdout
1336+
(with-stderr-to disable_class_type.ml.stderr
1337+
(run %{bin:ocamlformat} --margin-check %{dep:tests/disable_class_type.ml})))))
1338+
1339+
(rule
1340+
(alias runtest)
1341+
(package ocamlformat)
1342+
(action (diff tests/disable_class_type.ml disable_class_type.ml.stdout)))
1343+
1344+
(rule
1345+
(alias runtest)
1346+
(package ocamlformat)
1347+
(action (diff tests/disable_class_type.ml.err disable_class_type.ml.stderr)))
1348+
13311349
(rule
13321350
(deps tests/.ocamlformat )
13331351
(package ocamlformat)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class type c =
2+
let open [@ocamlformat "disable"] Z
3+
in
4+
z
5+
6+
class type c =
7+
object [@ocamlformat "disable"]
8+
end

0 commit comments

Comments
 (0)