Semantic Diff

#9498 Fix formatter moving an attribute off a type constraint

1 commit

69e11bfe7acda5984c1bf6bb2e7b10c320cd7df6..pr-9498

738c31747 · cknitt + Claude · Dec 01, 2026, 19:56 UTC

Fix formatter moving an attribute off a type constraint

Why

The printer printed the attributes of a type constraint in front of the constraint e: t, and the caller then put both in parentheses. Parsed again, the attribute applies to the first operand of e, so formatting changed the program: @warning("-102") ([1] == [2]: bool) became (@warning("-102") [1] == [2]: bool), where the attribute is on [1].

A constraint with attributes now prints its own parentheses inside the attributes, as a coercion already does. Where a constraint or coercion only needs parentheses for itself, such as a let value or an argument, no second pair is added around the attributes.

modifiedFormat attribute on a type constraint or coercion

let x = @attr (10: int)let y = @attr (v :> b)
rescript
Before
After
let x = (@attr 10: int)let y = (@attr (v :> b))let x = @attr (10: int)let y = @attr (v :> b)

Fixes #9497