Fix formatter forcing doc-commented inline-record exceptions onto multiple lines - #8622
Open
MavenRain wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c57cb29de
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…tiple lines (rescript-lang#7947) Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
MavenRain
force-pushed
the
fix/7947-exception-inline-record-doc-comment
branch
from
September 4, 2026 13:26
8c57cb2 to
b4daa71
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8622 +/- ##
==========================================
- Coverage 77.32% 77.32% -0.01%
==========================================
Files 467 467
Lines 63342 63313 -29
==========================================
- Hits 48982 48957 -25
+ Misses 14360 14356 -4
🚀 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #7947. A doc comment on an
exceptionwith an inline-record argument forced the record onto multiple lines. One line changes: the inline-record branch ofprint_constructor_argumentsnow wraps its argument doc in aDoc.group, exactly as the tuple branch already did.Problem
With a doc comment, the record is exploded:
printed as:
Nothing else in the same neighbourhood behaves this way. All four of these stay on one line today:
That asymmetry matches the issue thread. @nojaf asked:
and the reporter answered:
The cause is in
compiler/syntax/src/res_printer.ml, inprint_constructor_arguments. ThePcstr_tuplebranch ends with:while the
Pcstr_recordbranch ended with a bare:A doc comment is printed as a hard line break by
print_exception_def(and byprint_extension_constructor). Because the record argument had no group of its own, itssoft_lines sat in the same group as that hard break, so the forced break propagated into the record. The tuple branch was immune only because its group isolated it.Fix
Doc.rbrace; Doc.rparen; ] in - if indent then Doc.indent args else args + Doc.group (if indent then Doc.indent args else args)The two branches are now identical in this respect. Breaking still happens when the record genuinely does not fit in 100 columns, since the group breaks on width as usual.
The same code path serves extension constructors, so
type t += /** doc */ Ext({name: string, msg: string})keeps its record on one line for free.Two things are deliberately left alone:
force_breakfrom source locations, in the style ofprint_record_declaration. Separate change.|, on its own line. That is a different defect, tracked as switch-branch with multi-match branch is formatted weirdly #7962, and this PR does not touch it. The added fixture records today's behaviour so the change shows up plainly when switch-branch with multi-match branch is formatted weirdly #7962 is fixed.Testing
Printer fixtures added, with the expected files regenerated:
tests/syntax_tests/data/printer/structure/exception.res: doc-commented inline-record exceptions with one field and with two fields, plus a four-field case that is over 100 columns and still breaks.tests/syntax_tests/data/printer/signature/exception.resi: the same one-field and two-field cases in a signature.tests/syntax_tests/data/printer/structure/typeExtension.res: a doc-commented inline-record extension constructor.No existing expected file changed. The new group only takes effect when an enclosing group is already broken, which no previous fixture exercised.
Gates, all green:
ROUNDTRIP_TEST=1 ./scripts/test_syntax.sh: no unstaged test differences, roundtrip tests succeeded.bsc -formatover the CI file list: 1813 files checked, 0 need formatting.ocamlformat0.29.0 onres_printer.ml: clean.Manual check on the reported snippet: it prints on one line after the fix, and formatting the output a second time is idempotent.
AI-assisted; I reviewed and tested every change.