Skip to content

Commit 34fef8f

Browse files
cknittclaude
andcommitted
Detect doc comments on awaited functor arguments
An await node's own attributes print before it, so a doc comment on it starts the printed argument: F((/** doc */ (await X))) printed as F(/** doc */ (await X)), which doesn't parse. Only a functor's attributes print elsewhere (on its first parameter). Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 34dcaf3 commit 34fef8f

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎compiler/syntax/src/res_printer.ml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ let add_mod_expr_parens doc = Doc.concat [Doc.lparen; doc; Doc.rparen]
3737
constraint or application starts with its leftmost module *)
3838
let rec mod_expr_starts_with_doc_comment (mod_expr : Parsetree.module_expr) =
3939
match mod_expr.pmod_desc with
40-
(* [await] and a functor's parameter list come first *)
41-
| Pmod_await _ | Pmod_functor _ -> false
40+
(* A functor's attributes print on its first parameter *)
41+
| Pmod_functor _ -> false
4242
| _
4343
when List.exists Parsetree_viewer.is_doc_comment_attribute
4444
mod_expr.pmod_attributes ->
4545
true
4646
| _ when Parsetree_viewer.mod_expr_has_attributes mod_expr -> false
47+
(* Without attributes, [await] comes first *)
48+
| Pmod_await _ -> false
4749
| Pmod_constraint (inner, _) -> mod_expr_starts_with_doc_comment inner
4850
| Pmod_apply _ ->
4951
let _, call_expr = Parsetree_viewer.mod_expr_apply mod_expr in

‎tests/syntax_tests/data/printer/modExpr/attributes.res‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module V = @JSX (X: S)
3838
// a functor argument can't start with a doc comment
3939
module W = H(@w /** doc */ X)
4040
module Y = H((/** doc */ X: S))
41+
module AA = H((/** doc */ (await X)))
4142
module Z = /** doc */ X
4243
include /** doc */ X
4344

‎tests/syntax_tests/data/printer/modExpr/expected/attributes.res.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module V = @JSX (X: S)
4444
// a functor argument can't start with a doc comment
4545
module W = H((/** doc */ @w X))
4646
module Y = H((/** doc */ X: S))
47+
module AA = H((/** doc */ (await X)))
4748
module Z = /** doc */ X
4849
include /** doc */ X
4950

0 commit comments

Comments
 (0)