Fix functor module type result-signature brace formatting#8519
Fix functor module type result-signature brace formatting#8519MavenRain wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 77aaf8f19b
ℹ️ 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".
Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
|
|
||
| module ResultIdent: A => B | ||
|
|
||
| module ResultWith: A => (B with type t = int) |
There was a problem hiding this comment.
@MavenRain can you add module name with a longer name as well (more than 80 characters in one line) to test how the formatter handles that case?
There was a problem hiding this comment.
Added three long-name cases (each over 80 columns) to functorInterface.resi plus their golden output:
module ThisIsAVeryLongFunctorModuleTypeNameThatExceedsTheEightyCharacterLimit: Pattern => {
let fmt: event => string
}
module SecondVeryLongFunctorModuleTypeNameWithMultipleShortParameters: (A, B) => {
let x: int
}
module YetAnotherVeryLongFunctorModuleTypeNameHere: SomeVeryLongParameterModuleTypeName =>
SomeVeryLongResultingModuleTypeNameHow the formatter handles them:
- Signature results keep the brace hugged even past 80 columns (91 and 82 columns above). For
Name: Pattern => {there is no break point that could rescue the width anyway: before this fix the printer emitted the same overlong header minus the brace and then put{alone on the next line, so hugging costs 2 characters on an already-overlong line and matches how module-expression functors print. - Long non-signature results still wrap at the breakable line after
=>(third case); that path is untouched by this PR. - One trait the new golden makes visible: the second case's short parameter tuple stays flat rather than breaking to rescue the width. That behavior is not new here: master prints the same header flat (just with
{pushed to the next line), and module-expression functors keep short parameter tuples flat on comparable over-80-column headers as well. The fix only changes where the brace goes.
The full corpus regeneration shows no other golden moved, and the printer + idempotency roundtrip suite still passes; the new cases are idempotent. Reverting the fix breaks the new golden on exactly the two long-name signature cases, so they do exercise the changed code path.
Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
|
|
||
| module type B = () => | ||
| { | ||
| module type B = () => { |
There was a problem hiding this comment.
sorry I should be more explicit @MavenRain, can you also add a similar test here? Just need to be sure that both .res and .resi are handled correctly.
There was a problem hiding this comment.
Added the mirrored three cases to functor.res plus their golden output:
module type ThisIsAVeryLongFunctorModuleTypeNameThatExceedsTheEightyCharacterLimit = Pattern => {
let fmt: event => string
}
module type SecondVeryLongFunctorModuleTypeNameWithMultipleShortParameters = (A, B) => {
let x: int
}
module type YetAnotherVeryLongFunctorModuleTypeNameHere = SomeVeryLongParameterModuleTypeName =>
SomeVeryLongResultingModuleTypeNameThe .res output matches the .resi behavior shape for shape: signature results keep the brace hugged past 80 columns (97 and 88 columns here), the short parameter tuple stays flat, and the long non-signature result wraps at the break point after =>. The symmetry is structural: module type X = ... in .res and module X: ... in .resi both delegate to the same print_mod_type functor arm that this PR changed, so the brace placement rule is shared between the two syntaxes.
Full corpus regeneration moves no other golden, the printer + idempotency roundtrip suite still passes, and reverting the fix breaks this golden on exactly the two new signature-result cases (plus the pre-existing module type B = () => {} case), so the new cases do pin the changed code path on the .res side as well.
Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
Fix functor module type result-signature brace formatting
Fixes #7949.
Problem
When a functor module type returns a signature, the formatter broke the
opening brace onto its own line:
This is inconsistent with functor module expressions, which already keep the
brace on the same line as
=>:Cause
In
print_mod_type(thePmty_functorarm ofcompiler/syntax/src/res_printer.ml),the arrow was followed by a breakable
Doc.line. Because a signature resultforce-breaks internally, the enclosing group always broke at that
Doc.line,pushing
{to the next line. The siblingprint_mod_functor(moduleexpressions) uses an unconditional hard space (
Doc.text " => ") and so neverhad this problem.
Fix
When the functor result is a signature, use a hard space before it (hug the
brace); otherwise keep the breakable
Doc.lineso long non-signature results(idents,
withconstraints, curried arrows) can still wrap:Testing
tests/syntax_tests/data/printer/modType/functorInterface.resicovering the reported
.resicase plus curried params, a nested/curried arrow,an empty signature, and non-signature results (which must remain unchanged).
(
modType/functor.res.txtmodule type B = () => {, andmodExpr/structure.res.txtmodule G0: (X: {}) => {).make test-syntaxandmake test-syntax-roundtrippass; the printer +idempotency corpus round-trips with no diff, and comments around
=>/ insidethe result signature are preserved.
Drafted with AI assistance; the change, tests, and verification were reviewed by me.