Add explicit support for labeled tuples - #349
Merged
Merged
Conversation
Signed-off-by: Nathan Rebours <nathan.rebours@ocamlpro.com>
NathanReb
force-pushed
the
support-labeled-tuples
branch
from
July 31, 2026 14:30
b6404ea to
799f34a
Compare
AltGr
approved these changes
Aug 3, 2026
AltGr
left a comment
Contributor
There was a problem hiding this comment.
Seems pretty reasonable ; the depth limit to 100 might be a bit high, but that shouldn't affect anything. Thanks!
Signed-off-by: Nathan Rebours <nathan.rebours@ocamlpro.com>
Signed-off-by: Nathan Rebours <nathan.rebours@ocamlpro.com>
NathanReb
force-pushed
the
support-labeled-tuples
branch
from
August 4, 2026 07:48
799f34a to
a37292f
Compare
Signed-off-by: Nathan Rebours <nathan.rebours@ocamlpro.com>
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.
This PR adds tests for ocp-indent's behaviour with the labeled tuples syntax (introduced in OCaml 5.4: ocaml/ocaml#13498).
In expressions and patterns, ocp-indent was already correctly handling labeled tuples and no update were required.
In type expressions though it didn't as the type expression syntax for labels was too closely tied to arrows which resulted in the incorrect indentation of the following example:
which was misintepreted as
a: (int * b:int), assuming the labelawas a function argument label.Properly handling this isn't a trivial fix since determining how to indent it ultimately depends on whether there is an arrow up ahead.
e.g.:
should be indented as follows:
but
should be indented as follows:
to reflect
->and*priorities/associativity with the label.ocp-indentdoesn't handle backtracking and avoids lookahead as much as possible. I came to the conclusion that in this specific case, the lookahead was unavoidable so I tried to:*cannot be associated with a->I'll happily update and improve this approach based on user feedback. My gut feeling is that in practice this will work reasonably well though it might fail us in some corner cases.