Skip to content

Formatter moves an attribute in front of ~a as x: int onto x #9101

Closed

Description

@cristianoc

Found by a bug hunt over the 16 commits from eb087382 to cd641cbc.

let g = (@attr ~a as x: int) => x

bsc -format prints:

let g = (~a as @attr x: int) => x

The attribute is on the Ppat_constraint pattern before formatting and on the inner Ppat_var "x" after, so formatting changes the AST. The same happens at b123b7c3.

Since #9055 a doc comment is accepted in the same position, and it is printed in the same place:

let h = (/** a */ ~a as x: int=3) => x

prints as ~a as /** a */ with x: int=3 on the next line.

Cause

The ~b as c arm of print_exp_fun_parameter (res_printer.ml#L5650-L5658) prints ~lbl as, then the whole pattern including its attributes.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions