-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
[1;31mWe've found a bug for you![0m | ||
[36m/.../fixtures/curried_expected.res[0m:[2m3:24-38[0m | ||
|
||
1 [2m│[0m let expectCurried = f => f(1) + 2 | ||
2 [2m│[0m | ||
[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 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
let expectCurried = f => f(1) + 2 | ||
|
||
let z1 = expectCurried((. x, y) => x+y) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. |
||
(* Disable Unerasable_optional_argument for uncurried functions *) | ||
let unerasable_optional_argument = Warnings.number Unerasable_optional_argument in | ||
Warnings.parse_options false ("-" ^ string_of_int unerasable_optional_argument); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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). |
||
(if arityA = "1" then "argument" else "arguments") | ||
arityB | ||
(if arityB = "1" then "argument" else "arguments") | ||
arityA | ||
|
||
(* Pasted from typecore.ml. Needed for some cases in report_error below *) | ||
(* Records *) | ||
|
@@ -169,6 +169,11 @@ let report_error env ppf = function | |
(_, {desc = Tconstr (Pident {name = "function$"},_,_)}) :: _ | ||
) -> | ||
fprintf ppf "This function is a curried function where an uncurried function is expected" | ||
| Expr_type_clash ( | ||
(_, {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 commentThe reason will be displayed to describe this comment to others. Learn more. This avoids leaking |
||
| Expr_type_clash ( | ||
(_, {desc = Tconstr (Pident {name = "function$"},[_; tA],_)}) :: | ||
(_, {desc = Tconstr (Pident {name = "function$"},[_; tB],_)}) :: _ | ||
|
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.