Skip to content
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

Merged
merged 1 commit into from
Feb 4, 2023

Conversation

cristianoc
Copy link
Collaborator

@cristianoc cristianoc commented Feb 4, 2023

…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.

…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.
@@ -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;
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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"
Copy link
Collaborator Author

@cristianoc cristianoc Feb 4, 2023

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.

3 │ let z1 = expectCurried((. x, y) => x+y)
4 │

This function is an uncurried function where a curried function is expected
Copy link
Collaborator Author

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.

@cristianoc cristianoc merged commit 61e4db6 into master Feb 4, 2023
@cristianoc cristianoc deleted the uncurried_expected branch February 4, 2023 10:17
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.

None yet

1 participant