Skip to content

Commit d74aa84

Browse files
authored
fix error message on curried/uncurried signature mismatch (#6414)
* fix error msg on curried/uncurried sig mismatch * mark function curry kind in value mismatch * use expand_head to check type of functions * try passing tests in CI * Revert "try passing tests in CI" This reverts commit 1f1b4b8. * shorten test file names * shorten test file names even more
1 parent 232cf78 commit d74aa84

9 files changed

+151
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/c_for_u_in_c_mode.res:3:5-5:1
4+
5+
1 │ module Foo: {
6+
2 │ let add: (. int, int) => int
7+
3 │ } = {
8+
4 │  let add = (a, b) => a + b
9+
5 │ }
10+
6 │
11+
12+
Signature mismatch:
13+
Modules do not match:
14+
{
15+
let add: (int, int) => int
16+
}
17+
is not included in
18+
{
19+
let add: (. int, int) => int
20+
}
21+
Values do not match:
22+
let add: (int, int) => int (curried)
23+
is not included in
24+
let add: (. int, int) => int (uncurried)
25+
/.../fixtures/c_for_u_in_c_mode.res:2:3-30:
26+
Expected declaration
27+
/.../fixtures/c_for_u_in_c_mode.res:4:7-9:
28+
Actual declaration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/c_for_u_in_u_mode.res:5:5-8:1
4+
5+
3 │ module Foo: {
6+
4 │ let add: (int, int) => int
7+
5 │ } = {
8+
6 │  @@uncurried.swap
9+
7 │  let add = (. a, b) => a + b
10+
8 │ }
11+
9 │
12+
13+
Signature mismatch:
14+
Modules do not match:
15+
{
16+
let add: (int, int) => int
17+
}
18+
is not included in
19+
{
20+
let add: (int, int) => int
21+
}
22+
Values do not match:
23+
let add: (int, int) => int (curried)
24+
is not included in
25+
let add: (int, int) => int (uncurried)
26+
/.../fixtures/c_for_u_in_u_mode.res:4:3-28:
27+
Expected declaration
28+
/.../fixtures/c_for_u_in_u_mode.res:7:7-9:
29+
Actual declaration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/u_for_c_in_c_mode.res:3:5-5:1
4+
5+
1 │ module Foo: {
6+
2 │ let add: (int, int) => int
7+
3 │ } = {
8+
4 │  let add = (. a, b) => a + b
9+
5 │ }
10+
6 │
11+
12+
Signature mismatch:
13+
Modules do not match:
14+
{
15+
let add: (. int, int) => int
16+
}
17+
is not included in
18+
{
19+
let add: (int, int) => int
20+
}
21+
Values do not match:
22+
let add: (. int, int) => int (uncurried)
23+
is not included in
24+
let add: (int, int) => int (curried)
25+
/.../fixtures/u_for_c_in_c_mode.res:2:3-28:
26+
Expected declaration
27+
/.../fixtures/u_for_c_in_c_mode.res:4:7-9:
28+
Actual declaration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/u_for_c_in_u_mode.res:6:5-8:1
4+
5+
4 │ @@uncurried.swap
6+
5 │ let add: (. int, int) => int
7+
6 │ } = {
8+
7 │  let add = (a, b) => a + b
9+
8 │ }
10+
9 │
11+
12+
Signature mismatch:
13+
Modules do not match:
14+
{
15+
let add: (int, int) => int
16+
}
17+
is not included in
18+
{
19+
let add: (int, int) => int
20+
}
21+
Values do not match:
22+
let add: (int, int) => int (uncurried)
23+
is not included in
24+
let add: (int, int) => int (curried)
25+
/.../fixtures/u_for_c_in_u_mode.res:5:3-30:
26+
Expected declaration
27+
/.../fixtures/u_for_c_in_u_mode.res:7:7-9:
28+
Actual declaration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Foo: {
2+
let add: (. int, int) => int
3+
} = {
4+
let add = (a, b) => a + b
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@@uncurried
2+
3+
module Foo: {
4+
let add: (int, int) => int
5+
} = {
6+
@@uncurried.swap
7+
let add = (. a, b) => a + b
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Foo: {
2+
let add: (int, int) => int
3+
} = {
4+
let add = (. a, b) => a + b
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@@uncurried
2+
3+
module Foo: {
4+
@@uncurried.swap
5+
let add: (. int, int) => int
6+
} = {
7+
let add = (a, b) => a + b
8+
}

jscomp/ml/includemod.ml

+12-4
Original file line numberDiff line numberDiff line change
@@ -533,14 +533,22 @@ let show_locs ppf (loc1, loc2) =
533533
show_loc "Expected declaration" ppf loc2;
534534
show_loc "Actual declaration" ppf loc1
535535

536-
let include_err ppf = function
536+
let include_err ~env ppf = function
537537
| Missing_field (id, loc, kind) ->
538538
fprintf ppf "The %s `%a' is required but not provided" kind ident id;
539539
show_loc "Expected declaration" ppf loc
540540
| Value_descriptions(id, d1, d2) ->
541+
let curry_kind_1, curry_kind_2 =
542+
match (Ctype.expand_head env d1.val_type, Ctype.expand_head env d2.val_type ) with
543+
| { desc = Tarrow _ },
544+
{ desc = Tconstr (Pident {name = "function$"},_,_)} -> (" (curried)", " (uncurried)")
545+
| { desc = Tconstr (Pident {name = "function$"},_,_)},
546+
{ desc = Tarrow _ } -> (" (uncurried)", " (curried)")
547+
| _ -> ("", "")
548+
in
541549
fprintf ppf
542-
"@[<hv 2>Values do not match:@ %a@;<1 -2>is not included in@ %a@]"
543-
(value_description id) d1 (value_description id) d2;
550+
"@[<hv 2>Values do not match:@ %a%s@;<1 -2>is not included in@ %a%s@]"
551+
(value_description id) d1 curry_kind_1 (value_description id) d2 curry_kind_2;
544552
show_locs ppf (d1.val_loc, d2.val_loc);
545553
| Type_declarations(id, d1, d2, errs) ->
546554
fprintf ppf "@[<v>@[<hv>%s:@;<1 2>%a@ %s@;<1 2>%a@]%a%a@]"
@@ -633,7 +641,7 @@ let context ppf cxt =
633641

634642
let include_err ppf (cxt, env, err) =
635643
Printtyp.wrap_printing_env env (fun () ->
636-
fprintf ppf "@[<v>%a%a@]" context (List.rev cxt) include_err err)
644+
fprintf ppf "@[<v>%a%a@]" context (List.rev cxt) (include_err ~env) err)
637645

638646
let buffer = ref Bytes.empty
639647
let is_big obj =

0 commit comments

Comments
 (0)