Repository navigation
Fix formatter moving an attribute off a type constraint - #9498
Conversation
Changelog🐛 Bug fix
Semantic Diff1 commit · Full page ✏️ Fix formatter moving an attribute off a type constraint738c317 · cknitt + Claude · Dec 01, 2026, 19:56 UTC · edited
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. Format modified (attribute on a type constraint or coercion) let x = @attr (10: int)
let y = @attr (v :> b)
-let x = (@attr 10: int)
-let y = (@attr (v :> b))
+let x = @attr (10: int)
+let y = @attr (v :> b)Fixes #9497 |
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9498 +/- ##
=======================================
Coverage 82.49% 82.50%
=======================================
Files 467 467
Lines 66125 66127 +2
=======================================
+ Hits 54553 54555 +2
Misses 11572 11572
🚀 New features to boost your workflow:
|
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.
Format modified (attribute on a type constraint or coercion):
Example:
let x = @attr (10: int)
let y = @attr (v :> b)
Before (rescript):
let x = (@attr 10: int)
let y = (@attr (v :> b))
After (rescript):
let x = @attr (10: int)
let y = @attr (v :> b)
Fixes #9497
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gH9cXWp3xtBmfRV3Du
Signed-off-by: Christoph Knittel <ck@cca.io>
✅ Compiler benchmarksAllocated wordsIn total: 655,166,095 → 655,165,489 (±0.00%). Generated projects: 627,288,844 → 627,288,764 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 9,128,411,299 → 9,128,442,720 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,368,788 → 27,368,926 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 738c317 compared with base 69e11bf in this run. |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
719bc8d to
738c317
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9498 |
Fixes #9497.
The formatter changed what an attribute on a type constraint applies to:
was printed as
The printer printed the constraint's attributes in front of
e: t, and the caller then put both in parentheses. Parsed again, the attribute sits on[1], the first operand of==, instead of on the constraint.The fix. 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
letvalue or an argument,Res_parensno longer adds a second pair around the attributes. So the example stayslet a = @warning("-102") ([1] == [2]: bool), and a coercion prints as@foo (v :> b)instead of(@foo (v :> b)). As an operand, the attribute itself still needs parentheses:(@foo (v: int)) + 1.Tests. The existing printer test
constraint.reshad two inputs,@attr (10: int)and(@attr 10: int), that the old printer printed identically; they now print differently. New cases cover a constraint with an attribute as aletvalue, an argument, an operand and inside braces. The format check of the whole repository passes unchanged.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gH9cXWp3xtBmfRV3Du