Skip to content

Commit ff18cec

Browse files
committed
adjust messages
1 parent de87848 commit ff18cec

22 files changed

+98
-78
lines changed

compiler/ml/typecore.ml

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4259,15 +4259,18 @@ let report_error env ppf error =
42594259
| _ ->
42604260
fprintf ppf
42614261
"@[<v>@[<2>This can't be called, it's not a function.@]@,\
4262-
It has type: %a@]"
4262+
The function has type: %a@]"
42634263
type_expr typ)
42644264
| Apply_wrong_label (l, ty) ->
4265-
let print_label ppf = function
4266-
| Noloc.Nolabel -> fprintf ppf "an unlabelled argument at this position"
4267-
| l -> fprintf ppf "the argument @{<info>%s@}" (prefixed_label_name l)
4265+
let print_message ppf = function
4266+
| Noloc.Nolabel ->
4267+
fprintf ppf "The argument at this position should be labelled."
4268+
| l ->
4269+
fprintf ppf "This function does not take the argument @{<info>%s@}."
4270+
(prefixed_label_name l)
42684271
in
4269-
fprintf ppf "@[<v>@[<2>This function does not take %a.@]@,It has type: %a@]"
4270-
print_label l type_expr ty
4272+
fprintf ppf "@[<v>@[<2>%a@]@,This function has type: %a@]" print_message l
4273+
type_expr ty
42714274
| Label_multiply_defined {label; jsx_component_info = Some jsx_component_info}
42724275
->
42734276
fprintf ppf
@@ -4482,9 +4485,10 @@ let report_error env ppf error =
44824485
&& mismatch_in_unlabelled_args = false
44834486
in
44844487
4485-
if is_fallback then
4486-
fprintf ppf "@[<v>@[<2>This function call is incorrect.@]"
4487-
else fprintf ppf "@[<v>@[<2>This function call is incorrect:@]";
4488+
fprintf ppf "@[<v>@[<2>This function call is incorrect.@]";
4489+
fprintf ppf "@,The function has type:@ %a" type_expr typ;
4490+
4491+
if not is_fallback then fprintf ppf "@,";
44884492
44894493
if List.length missing_required_args > 0 then
44904494
fprintf ppf "@,- Missing arguments that must be provided: %s"
@@ -4496,21 +4500,22 @@ let report_error env ppf error =
44964500
fprintf ppf "@,- Called with arguments it does not take: %s"
44974501
(superfluous_args |> String.concat ", ");
44984502
4503+
let unlabelled_msg a b pos =
4504+
match (a, pos) with
4505+
| 0, `left -> "no"
4506+
| 0, `right -> "none"
4507+
| _ when a > b -> string_of_int a
4508+
| _ -> "just " ^ string_of_int a
4509+
in
4510+
44994511
if mismatch_in_unlabelled_args then
45004512
fprintf ppf
45014513
"@,\
4502-
- It takes @{<info>%s@} unlabelled argument%s, but is called with \
4503-
@{<error>%s@}"
4504-
(if args_from_type_unlabelled > sargs_unlabelled then
4505-
string_of_int args_from_type_unlabelled
4506-
else "just " ^ string_of_int args_from_type_unlabelled)
4514+
- The function takes @{<info>%s@} unlabelled argument%s, but is \
4515+
called with @{<error>%s@}"
4516+
(unlabelled_msg args_from_type_unlabelled sargs_unlabelled `left)
45074517
(if args_from_type_unlabelled = 1 then "" else "s")
4508-
(if sargs_unlabelled > args_from_type_unlabelled then
4509-
string_of_int sargs_unlabelled
4510-
else "just " ^ string_of_int sargs_unlabelled);
4511-
4512-
if not is_fallback then fprintf ppf "@,";
4513-
fprintf ppf "@,The function has type:@ %a" type_expr typ;
4518+
(unlabelled_msg sargs_unlabelled args_from_type_unlabelled `right);
45144519
45154520
(* Print fallback if nothing above matched *)
45164521
if is_fallback then

tests/build_tests/super_errors/expected/arity_mismatch.res.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
2 │ let makeVariables = makeVar(~f=f => f)
77
3 │
88

9-
This function call is incorrect:
10-
- It takes 1 unlabelled argument, but is called with just 0
11-
9+
This function call is incorrect.
1210
The function has type:
13-
(~f: 'a => 'a, unit) => int
11+
(~f: 'a => 'a, unit) => int
12+
13+
- The function takes 1 unlabelled argument, but is called with none

tests/build_tests/super_errors/expected/arity_mismatch2.res.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
2 │ let makeVariables = makeVar(1, 2, 3)
77
3 │
88

9-
This function call is incorrect:
10-
- It takes just 2 unlabelled arguments, but is called with 3
11-
9+
This function call is incorrect.
1210
The function has type:
13-
('a, unit) => int
11+
('a, unit) => int
12+
13+
- The function takes just 2 unlabelled arguments, but is called with 3
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/arity_mismatch4.res:2:21-27
4+
5+
1 │ let makeVar = (~f) => 34
6+
2 │ let makeVariables = makeVar(1, ~f=f => f)
7+
3 │
8+
9+
This function call is incorrect.
10+
The function has type:
11+
(~f: 'a) => int
12+
13+
- The function takes no unlabelled arguments, but is called with 1

tests/build_tests/super_errors/expected/fun_return_poly1.res.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
4 │ let err = f(1, 2)
2020
5 │
2121

22-
This function does not take an unlabelled argument at this position.
23-
It has type: ('a, ~def: int=?) => 'b
22+
The argument at this position should be labelled.
23+
This function has type: ('a, ~def: int=?) => 'b

tests/build_tests/super_errors/expected/fun_return_poly2.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
8 │
2121

2222
This function does not take the argument ~initialValue.
23-
It has type: (string, ~wrongLabelName: int=?) => 'a
23+
This function has type: (string, ~wrongLabelName: int=?) => 'a

tests/build_tests/super_errors/expected/missing_label.res.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
3 │ let _ = f("")
88
4 │
99

10-
This function does not take an unlabelled argument at this position.
11-
It has type: (~a: string) => string
10+
The argument at this position should be labelled.
11+
This function has type: (~a: string) => string

tests/build_tests/super_errors/expected/missing_labels.res.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
3 │ let _ = f("", "")
88
4 │
99

10-
This function does not take an unlabelled argument at this position.
11-
It has type: (~a: string, ~b: string) => string
10+
The argument at this position should be labelled.
11+
This function has type: (~a: string, ~b: string) => string

tests/build_tests/super_errors/expected/moreArguments1.res.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
2 │ let y = x(~a=2) + 2
77
3 │
88

9-
This function call is incorrect:
10-
- Missing arguments that must be provided: ~b
11-
9+
This function call is incorrect.
1210
The function has type:
13-
(~a: int, ~b: int) => int
11+
(~a: int, ~b: int) => int
12+
13+
- Missing arguments that must be provided: ~b

tests/build_tests/super_errors/expected/moreArguments2.res.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
2 │ let y = x(2) + 2
77
3 │
88

9-
This function call is incorrect:
10-
- It takes 2 unlabelled arguments, but is called with just 1
11-
9+
This function call is incorrect.
1210
The function has type:
13-
(int, int) => int
11+
(int, int) => int
12+
13+
- The function takes 2 unlabelled arguments, but is called with just 1

0 commit comments

Comments
 (0)