13034 error messages: mismatched labels#13260
Conversation
typing/ctype.ml
Outdated
| | false, false -> link_commu ~inside:c1 c2 | ||
| | true, true -> () | ||
| end else | ||
| raise_for Unify (Function_label_mismatch {got=l1; expected=l2}) |
There was a problem hiding this comment.
Nitpick: wouldn't this be easier on the eye with the error case first?
if not (compatible_labels ...) then
raise_for ...;
unify uenv t1 t2; unify uenv u1 u2;
begin match ... with
...
end(Same question in the other, simpler cases.)
There was a problem hiding this comment.
Woudn't it be even simpler if we moved the raise inside the compatible_labels function ?
This would reduce code duplication (and even more if more label comparison are added).
There was a problem hiding this comment.
There are calls to compatible_labels in mcomp and the subtyping mode that doesn't raise the exception, either because we are only checking compatibility or because we are storing an error trace for later use.
However, we could have a raise_on_incompatible_labels function which has the advantage of keeping the control flow obvious.
gasche
left a comment
There was a problem hiding this comment.
I am uneasy with the wording The optional argument "?x", because ?x is a label and not an argument`. I proposed some reformulations that avoid this issue. Also in the case of a mismatch between an optional and a non-optional label, I propose to simplify with a more approximative but shorter error message. Feel free to adapt the suggestions or discard them outright.
| is not included in | ||
| type t = int -> int | ||
| The type "x:int -> int" is not equal to the type "int -> int" | ||
| The argument "x" is labeled, but an unlabeled argument was expected |
There was a problem hiding this comment.
Proposal: The argument has label "x", but ....
There was a problem hiding this comment.
Counterproposal: The first argument is labeled "x"
| is not included in | ||
| val f : int -> unit | ||
| The type "x:'a -> unit" is not compatible with the type "int -> unit" | ||
| The argument "x" is labeled, but an unlabeled argument was expected |
| is not included in | ||
| val f : int -> unit | ||
| The type "?x:'a -> unit" is not compatible with the type "int -> unit" | ||
| The argument "?x" is optional, but an unlabeled argument was expected |
| is not included in | ||
| val f : x:int -> unit | ||
| The type "?x:'a -> unit" is not compatible with the type "x:int -> unit" | ||
| The optional argument "?x" was not expected to be optional |
There was a problem hiding this comment.
Labels "?x" and "x" do not match.
There was a problem hiding this comment.
I disagree with repeating twice the same name with one minute change.
I propose: Label "?x" was expected to not be optional.
There was a problem hiding this comment.
Wait, what would the error be on a mismatch between ?x:int -> unit and y:int -> unit? I assumed that the use of x on both sides was irrelevant to the current situation and wording.
There was a problem hiding this comment.
In this case, Labels "?x" and "y" do not match seems a good simplification to me (the previous error message was The optional argument "?x" was expected to be a labeled argument named "y")
| is not included in | ||
| val f : ?x:int -> unit | ||
| The type "'a -> unit" is not compatible with the type "?x:int -> unit" | ||
| An optional argument "?x" was expected |
| but an expression was expected of type "unit -> unit" | ||
| The argument "x" is labeled, but an unlabeled argument was expected | ||
| The first argument is labeled "x", | ||
| but an unlabeled argument was expected |
There was a problem hiding this comment.
Side remark: the absence of a final . at the end of these captialized sentences is odd, but this is orthogonal to the current change.
There was a problem hiding this comment.
I agree and generally struggle to remember to not add period in those explanations.
This PR adds a specialized explanation for mismatched function labels in type error messages.
For instance, in
the existing error message
is extended with
This complements the existing specialized error message for syntactic argument with a label incompatible with the expected type.
close #13034