Skip to content

Conversation

@WardBrian
Copy link
Contributor

@WardBrian WardBrian commented Oct 30, 2025

Follow-on to #2746, this makes it so the letop-punning setting also affects nodes like let%foo bar = bar in ...

The trickiest piece here is that the ands for these nodes don't have the extension, so I needed to do this at the level of value_bindings, not value_binding

This also fixes an issue with comments when a pun is introduced. As far as I can tell, this was also an issue back in 0.26, when the equivalent of letop-punning=always was the default behavior.

@WardBrian
Copy link
Contributor Author

(note I commented in #2746 that I thought the preserve feature would require parser changes, but it turns out the parser already was tracking this, my tests were just lacking any examples of it)

@WardBrian
Copy link
Contributor Author

Hi @EmileTrotignon - I think this is ready for review. The let%ext change is very similar to the code from the previous PR and should be an easy review.

A bit trickier is I noticed that letop-punning=always could lead to errors if the right hand side had associated comments. I believe I found a fix (for both this new code and the existing), but I'm less confident in that part and would appreciate any pointers

@EmileTrotignon
Copy link
Collaborator

This looks good. Where is the fix about comments ?

@WardBrian
Copy link
Contributor Author

The way I tackled the comment issue is by copying the location of the rhs into the pattern (starting in efb3931). I’m not sure if this is the recommended way or not, but it does appear to work on the added test cases

Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

Awesome :)

@WardBrian
Copy link
Contributor Author

@Julow I split out the testing and CONTRIBUTING changes into #2748 and then rebased this PR off of that one to try
to make review easier.

I'm now calling Cmts.relocate in Sugar.ml, which seems to be working well

Copy link
Collaborator

@EmileTrotignon EmileTrotignon left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the contributing documentation, its a very big improvement.

@EmileTrotignon
Copy link
Collaborator

Sorry I reviewed the contribution.md changes in the wrong PR

@WardBrian
Copy link
Contributor Author

No worries @EmileTrotignon. I've pushed updates to #2748

(stacked PRs still need a better workflow for github -- the diffs quickly diverge without a lot of ugly force pushing)

@WardBrian WardBrian force-pushed the feat/let-punning-for-extensions branch from 68d651a to 18c3a3f Compare November 3, 2025 16:17
@WardBrian WardBrian requested a review from Julow November 3, 2025 19:22
@WardBrian WardBrian force-pushed the feat/let-punning-for-extensions branch from 18c3a3f to 1fe36f0 Compare November 3, 2025 19:24
Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

Looks perfect :) Let's merge just after #2748

@EmileTrotignon
Copy link
Collaborator

This can be merged after a rebase on main

WardBrian and others added 3 commits November 5, 2025 10:38
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@WardBrian WardBrian force-pushed the feat/let-punning-for-extensions branch from 1fe36f0 to 425ecc4 Compare November 5, 2025 15:40
@WardBrian
Copy link
Contributor Author

Rebased :)

@EmileTrotignon
Copy link
Collaborator

Waiting for CI and merging

@WardBrian
Copy link
Contributor Author

CI has passed. Thanks for the hand-holding on this feature!

@EmileTrotignon EmileTrotignon merged commit 295fe67 into ocaml-ppx:main Nov 6, 2025
11 of 12 checks passed
@EmileTrotignon
Copy link
Collaborator

@WardBrian You're very welcome ! If you are interested in contributing further to ocamlformat, maybe we could have a chat about the project.

@WardBrian WardBrian deleted the feat/let-punning-for-extensions branch November 7, 2025 15:07
@WardBrian
Copy link
Contributor Author

Sure @EmileTrotignon! I've been a happy user of ocamlformat for years, and this is the first time I found a gap in my needs for it that prompted me to contribute, but I have some spare cycles to do more here or there

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.

3 participants