Skip to content

Keep the header of a let with locally abstract types on one line - #9082

Merged
cknitt merged 1 commit into
ocaml-feature-testsfrom
fix-9070-locally-abstract-let-format
Oct 29, 2026
Merged

cknitt merged 1 commit into
ocaml-feature-testsfrom
fix-9070-locally-abstract-let-format

Conversation

@cknitt

@cknitt cknitt commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Fixes #9070. Stacked on #9076, whose new test files this reformats.

The formatter printed a binding annotated with type a. as one group, so a multi-line body broke the header after : and = and indented the body twice. Now the header stays on one line when its first line fits:

let rec eval: type a. expr<a> => a = e =>
  switch e {
  | Int(n) => n
  }

A header that doesn't fit is printed as before. The printer fixture newtype.res gains cases for both, also with a doc comment and attribute in front.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gLMawVgtmiKy3TMBc3

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • The formatter keeps let f: type a. t => a = x => on one line when it fits, instead of breaking after : and = whenever the body spans several lines.

Semantic Diff

1 commit · Full page

✏️ Keep the header of a let with locally abstract types on one line

3a28be2 · cknitt + Claude · Oct 27, 2026, 12:50 UTC · edited

Why

A binding annotated with type a. was printed as one group, so a line break in its body, such as a switch, broke the header after : and = as well and indented the body twice. This is how every function over a GADT is written. The header now stays on one line when its first line fits, as for other annotated bindings.

Format modified (let with locally abstract types)

let rec eval: type a. expr<a> => a = e =>
  switch e {
  | Int(n) => n
  | Bool(b) => b
  }

rescript

-let rec eval:
-  type a. expr<a> => a =
-  e =>
-    switch e {
-    | Int(n) => n
-    | Bool(b) => b
-    }
+let rec eval: type a. expr<a> => a = e =>
+  switch e {
+  | Int(n) => n
+  | Bool(b) => b
+  }

Review

  • What happens to a header that doesn't fit? It is printed as before, broken after : and =; the printer fixture keeps such a case, also with attributes in front, which stay outside the layout choice so that the header's width is measured from the let.

@cknitt
cknitt added this pull request to stack #9088 October 27, 2026 13:15
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.69%. Comparing base (09be8ce) to head (3a28be2).

Additional details and impacted files
@@                 Coverage Diff                  @@
##           ocaml-feature-tests    #9082   +/-   ##
====================================================
  Coverage                81.69%   81.69%           
====================================================
  Files                      460      460           
  Lines                    64728    64733    +5     
====================================================
+ Hits                     52879    52884    +5     
  Misses                   11849    11849           
Files with missing lines Coverage Δ
compiler/syntax/src/res_printer.ml 94.60% <100.00%> (+<0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9082

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9082

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9082

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9082

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9082

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9082

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9082

commit: 3a28be2

@cknitt
cknitt marked this pull request as ready for review October 27, 2026 14:20
@cknitt

cknitt commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T14:22:11.472692Z 23146ca Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 23146ca981

ℹ️ 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".

@cknitt
cknitt force-pushed the fix-9070-locally-abstract-let-format branch from 23146ca to fe33a6f Compare October 28, 2026 08:10
Why:
    A binding annotated with `type a.` was printed as one group, so a line
    break in its body, such as a switch, broke the header after `:` and
    `=` as well and indented the body twice. This is how every function
    over a GADT is written. The header now stays on one line when its
    first line fits, as for other annotated bindings.

Format modified (let with locally abstract types):
Example:
    let rec eval: type a. expr<a> => a = e =>
      switch e {
      | Int(n) => n
      | Bool(b) => b
      }
Before (rescript):
    let rec eval:
      type a. expr<a> => a =
      e =>
        switch e {
        | Int(n) => n
        | Bool(b) => b
        }
After (rescript):
    let rec eval: type a. expr<a> => a = e =>
      switch e {
      | Int(n) => n
      | Bool(b) => b
      }

Review: What happens to a header that doesn't fit?
    It is printed as before, broken after `:` and `=`; the printer
    fixture keeps such a case, also with attributes in front, which stay
    outside the layout choice so that the header's width is measured
    from the `let`.

Fixes: #9070
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gLMawVgtmiKy3TMBc3
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the fix-9070-locally-abstract-let-format branch from fe33a6f to 3a28be2 Compare October 29, 2026 13:22
@cknitt
cknitt requested a review from cristianoc October 29, 2026 13:56

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for the changes.

@cknitt
cknitt merged commit 9ceeb96 into master Oct 29, 2026
26 checks passed
@cknitt
cknitt deleted the fix-9070-locally-abstract-let-format branch October 29, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter breaks let f: type a. ... = headers when the body spans several lines

2 participants