Print coercions with context-aware parentheses - #8614
Conversation
Signed-off-by: Christoph Knittel <ck@cca.io>
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. |
Signed-off-by: Christoph Knittel <ck@cca.io>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 00d09b5a27
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
Signed-off-by: Christoph Knittel <ck@cca.io>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8614 +/- ##
=======================================
Coverage 77.58% 77.59%
=======================================
Files 475 475
Lines 64062 64073 +11
=======================================
+ Hits 49704 49718 +14
+ Misses 14358 14355 -3
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/darwin-x64
@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-8614 |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df3784c572
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
Signed-off-by: Christoph Knittel <ck@cca.io>
…ntheses Signed-off-by: Christoph Knittel <ck@cca.io> # Conflicts: # compiler/syntax/src/res_printer.ml
Signed-off-by: Christoph Knittel <ck@cca.io>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c808a09fa6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| in | ||
| let doc_typ = print_typ_expr ~state typ cmt_tbl in | ||
| Doc.concat [Doc.lparen; doc_expr; Doc.text " :> "; doc_typ; Doc.rparen] | ||
| let doc = Doc.concat [doc_expr; Doc.text " :> "; doc_typ] in |
There was a problem hiding this comment.
Preserve coercion grouping in plain-expression delimiters
When a coercion is the sole expression in an attribute/extension payload (for example, @a((x :> t))) or in unpack((x :> t)), removing the coercion's own parentheses produces @a(x :> t) or unpack(x :> t). Those contexts ultimately invoke plain parse_expr (parse_structure_item_region for the payload and parse_atomic_module_expr for unpack), which leaves :> unconsumed, so formatting valid input makes it fail to reparse; these printers need to apply Parens.expr or otherwise retain the inner grouping.
AGENTS.md reference: AGENTS.md:L135-L139
Useful? React with 👍 / 👎.
The formatter currently turns
foo(v :> b)intofoo((v :> b)). Reuse the existing parentheses rules to omit unnecessary parentheses in calls, collections, and array indices while preserving grouping where required.Keep parentheses for binding right-hand sides, arrow bodies, operators, field access, block sequences, constrained operands, and attributes. Bindings remain parenthesized because a following JSX element can otherwise be parsed as coercion type arguments. The parser is unchanged.
Add regression coverage for constrained operands and bindings followed by JSX, and reformat existing sources affected by the new rules.
Validation:
make test,make checkformat,make test-syntax, andmake test-syntax-roundtrip, plus structure-preservation and formatting-stability checks at widths 20, 80, and 100.Fixes #6254.