Repository navigation
Conversation
Why:
The parser puts attributes written before `~a as x` on the alias
pattern, and the formatter printed them after `as`, where they parse
onto the inner pattern, so formatting changed the AST (#9101). Doc
comments in that position were printed between `as` and the pattern.
Format modified (labeled parameter alias):
Example:
let g = (@attr ~a as x: int) => x
let h = (/** a */ ~a as x: int=3) => x
Before (rescript):
let g = (~a as @attr x: int) => x
let h = (
~a as /** a */
x: int=3,
) => x
After (rescript):
let g = (@attr ~a as x: int) => x
let h = (
/** a */
~a as x: int=3,
) => x
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP
Signed-off-by: Christoph Knittel <ck@cca.io>
Changelog🐛 Bug fix
Semantic Diff1 commit · Full page Keep attributes in front of a labeled parameter alias when formatting1b247dc · cknitt + Claude · Oct 28, 2026, 15:25 UTC
Format modified (labeled parameter alias) let g = (@attr ~a as x: int) => x
let h = (/** a */ ~a as x: int=3) => x
-let g = (~a as @attr x: int) => x
+let g = (@attr ~a as x: int) => x
let h = (
- ~a as /** a */
- x: int=3,
+ /** a */
+ ~a as x: int=3,
) => x |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9111 +/- ##
=======================================
Coverage 81.46% 81.46%
=======================================
Files 460 460
Lines 64675 64676 +1
=======================================
+ Hits 52689 52690 +1
Misses 11986 11986
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9111 |
|
@codex review |
Codex Review SummaryThis 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. Already looking forward to the next diff. 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". |
Formatting
let g = (@attr ~a as x: int) => xproducedlet g = (~a as @attr x: int) => x, which is a different AST: the parser puts attributes written before~a ason the whole alias pattern (here thePpat_constraint), while afterasthey attach to the innerx. A doc comment in the same position (accepted since #9055) was printed betweenasand the pattern, on its own line.The
~b as ccase ofprint_exp_fun_parameternow prints the pattern's own attributes before~, and the pattern without them afteras, like the punned~aand~a: tcases already do. Attributes that belong to an inner pattern (~a as @attr x: int) are untouched.Tests:
printer/expr/fun.resgains labeled aliases with attributes on constrained, optional, defaulted, tuple, record, wildcard and parenthesized patterns, plus one with the attribute on the inner pattern that must stay put;printer/comments/docCommentParameters.resgains a doc comment before a typed alias with a default. The existingasyncAwait.resanddocCommentParameters.ressnapshots now print the attribute and doc comment before the label.Fixes #9101
🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP