Skip to content

Parenthesize lambda in non-last record field on single line#3247

Merged
nojaf merged 3 commits intofsprojects:mainfrom
AgricoZA:fix/1659-record-lambda-single-line
Mar 7, 2026
Merged

Parenthesize lambda in non-last record field on single line#3247
nojaf merged 3 commits intofsprojects:mainfrom
AgricoZA:fix/1659-record-lambda-single-line

Conversation

@randrag
Copy link
Copy Markdown
Contributor

@randrag randrag commented Mar 5, 2026

When a record expression is collapsed to a single line, a fun lambda in a non-last field produces invalid F# because the lambda body extends to the end of the expression, swallowing subsequent fields.

This wraps such lambdas in parentheses, matching the existing approach used for tuple expressions (IsLambdaOrIfThenElse check in genExpr for ExprTupleNode).

Fixes #3246

Please verify your pull request is respecting our Pull request ground rules.

When a record expression is collapsed to a single line, a `fun` lambda
in a non-last field produces invalid F# because the lambda body extends
to the end of the expression, swallowing subsequent fields. Wrap such
lambdas in parentheses, matching the existing approach for tuples.

Fixes fsprojects#3246

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 6, 2026

🤖 This is an automated response from Repo Assist.

Welcome to Fantomas, @randrag! 🎉 Thank you for your first contribution — a well-documented soundness bug with a ready fix is exactly what the project needs.

Your analysis is spot on: in F#, fun extends to the end of the enclosing expression, so when a record is collapsed to a single line, the lambda body swallows subsequent fields. Wrapping the lambda in parentheses is the correct fix, and it's good to see you've matched the existing approach used for tuple expressions (IsLambdaOrIfThenElse in genExpr).

A few tips for a smooth review:

  • Please verify your PR follows the Pull Request Ground Rules
  • Make sure to include a dedicated test case that directly exercises this issue (a test named something like record with lambda in non-last field should be parenthesized on single line, 3246 would be great)
  • The CONTRIBUTING.md has useful guidance for navigating the codebase

Looking forward to seeing this reviewed and merged!

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@10f087607af87e4e89439161f1e5d4724235f396

@nojaf
Copy link
Copy Markdown
Contributor

nojaf commented Mar 6, 2026

Hi @randrag, thanks for the PR, this looks reasonable.
Ready for review or do you plan to do some more work on this?

@randrag randrag marked this pull request as ready for review March 6, 2026 14:40
@randrag
Copy link
Copy Markdown
Contributor Author

randrag commented Mar 7, 2026

Hi @nojaf, I'm happy with it as it is.

Thank you so much for Fantomas, which we have recently adopted to our solution of more than 2,000 F# files.

This was the only bug we picked up when initially reformatting them all.

Regards

Roland

@nojaf
Copy link
Copy Markdown
Contributor

nojaf commented Mar 7, 2026

Hi @randrag, would it be okay if I am allowed to push to your branch?
Had one minor nit that I changed and bumped the changelog.
Would push and merge that and publish a new alpha.

I think I can't push because this is coming from an organization fork?
Anyway, will deal with it in another branch.

@nojaf
Copy link
Copy Markdown
Contributor

nojaf commented Mar 7, 2026

Thank you so much for Fantomas, which we have recently adopted to our solution of more than 2,000 F# files.

Thanks for your kind words 😊!

Also cool to see that this was the only problem you had!

@nojaf nojaf enabled auto-merge March 7, 2026 17:42
@nojaf nojaf merged commit f09a97e into fsprojects:main Mar 7, 2026
10 of 11 checks passed
@randrag randrag deleted the fix/1659-record-lambda-single-line branch April 11, 2026 21:41
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.

Record with lambda in non-last field collapses to single line producing invalid code

2 participants