-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue with error messages for uncurried functions where expected … #5973
Conversation
…and given type were swapped The logic for unification for `Function$`, which unifies with a generic uncurried type, was swapped. The error message for arity mismatch was also swapped, so those errors were showing correctly. However, in the case of expected curried function, when given a curried function whose type is begin inferred, the error message was swapped. Also added a specialized error message when the uncurried type only contains a type variable, so `$function<'a, ...>` does not leak in the output. This happens as unification failt early, and the type of the function has not been determined yet.
ef6bf7b
to
3cd76e2
Compare
@@ -2107,7 +2107,7 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected = | |||
let state = Warnings.backup () in | |||
let arity = Ast_uncurried.attributes_to_arity sexp.pexp_attributes in | |||
let uncurried_typ = Ast_uncurried.make_uncurried_type ~env ~arity (newvar()) in | |||
unify_exp_types loc env ty_expected uncurried_typ; | |||
unify_exp_types loc env uncurried_typ ty_expected; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected type goes on the rhs, just like other instances in this file.
@@ -121,9 +121,9 @@ end | |||
|
|||
let reportArityMismatch ~arityA ~arityB ppf = | |||
fprintf ppf "This function expected @{<info>%s@} %s, but got @{<error>%s@}" | |||
arityA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was swapped, not swapping it back so it's consistent with the other error messages (A is the given one, and B is the expected).
(_, {desc = Tconstr (Pident {name = "function$"}, [{desc=Tvar _}; _],_)}) :: | ||
(_, {desc = Tarrow _}) :: _ | ||
) -> | ||
fprintf ppf "This function is an uncurried function where a curried function is expected" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This avoids leaking $function<'a, ...>
and talks about "an uncurried function" generically.
[1;31m3[0m [2m│[0m let z1 = expectCurried([1;31m(. x, y) => x+y[0m) | ||
4 [2m│[0m | ||
|
||
This function is an uncurried function where a curried function is expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message used to say the exact opposite before this PR.
…and given type were swapped
The logic for unification for
Function$
, which unifies with a generic uncurried type, was swapped. The error message for arity mismatch was also swapped, so those errors were showing correctly. However, in the case of expected curried function, when given an uncurried function whose type is begin inferred, the error message was swapped.Also added a specialized error message when the uncurried type only contains a type variable, so
$function<'a, ...>
does not leak in the output. This happens as unification fails early, and the type of the function has not been determined yet.