Skip to content

error messages: also point tuple label mismatches - #14070

Merged
dra27 merged 2 commits into
ocaml:trunkfrom
Octachron:mismatched_tuple_labels
Jun 5, 2025
Merged

dra27 merged 2 commits into
ocaml:trunkfrom
Octachron:mismatched_tuple_labels

Conversation

@Octachron

Copy link
Copy Markdown
Member

This small PR aligns the error message for mismatched labels in labelled tuples with the one for
mismatched labels in labelled function arguments.

In other words, it adds after the current error message

Error: This expression has type "a:string * int * c:'a"
      but an expression was expected of type "a:string * int * b:string"

a new line

Error: This expression has type "a:string * int * c:'a"
      but an expression was expected of type "a:string * int * b:string"
      Labels "c" and "b" do not match

to highlight that it is the labels b and c that are mismatched.
This mirrors the current error message for labelled function argument:

Error: The value x has type a:string -> int -> c:'a -> unit
      but an expression was expected of type
        a:string -> int -> b:string -> unit
      Labels c and b do not match

I personally tend to consider that this is quite close to an error message bug, and we may want to backport the fix to 5.4 .

@gasche gasche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is clearly reasonable. Approved. I think that backporting is reasonable, especially as the feature will be new in this release.

I thought a bit about why we didn't catch this during the review of the original implementation. I suppose that adding new raise_unexplained_for calls should be a review red/orange flag; to keep in mind for later.

@Octachron

Copy link
Copy Markdown
Member Author

Well, I found the issue by working on my plan to remove raise_unexplained_for, so the potential risk may disappear in the future.

@dra27
dra27 merged commit 688eabb into ocaml:trunk Jun 5, 2025
dra27 added a commit that referenced this pull request Jun 5, 2025
error messages: also point tuple label mismatches

(cherry picked from commit 688eabb)
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