Skip to content

Commit 018b17d

Browse files
committed
use expand_head to check type of functions
1 parent b6efc4c commit 018b17d

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

jscomp/ml/includemod.ml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -533,28 +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
540-
| Value_descriptions(id,
541-
({ val_type = { desc = Tlink { desc = Tconstr (Pident {name = "function$"},_,_) }}} as d1),
542-
({ val_type = { desc = Tarrow _ }} as d2)) ->
543-
fprintf ppf
544-
"@[<hv 2>Values do not match:@ %a (uncurried)@;<1 -2>is not included in@ %a (curried)@]"
545-
(value_description id) d1 (value_description id) d2;
546-
show_locs ppf (d1.val_loc, d2.val_loc)
547-
| Value_descriptions(id,
548-
({ val_type = { desc = Tlink { desc = Tarrow _ }}} as d1),
549-
({ val_type = { desc = Tconstr (Pident {name = "function$"},_,_)}} as d2)) ->
550-
fprintf ppf
551-
"@[<hv 2>Values do not match:@ %a (curried)@;<1 -2>is not included in@ %a (uncurried)@]"
552-
(value_description id) d1 (value_description id) d2;
553-
show_locs ppf (d1.val_loc, d2.val_loc)
554540
| 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
555549
fprintf ppf
556-
"@[<hv 2>Values do not match:@ %a@;<1 -2>is not included in@ %a@]"
557-
(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;
558552
show_locs ppf (d1.val_loc, d2.val_loc);
559553
| Type_declarations(id, d1, d2, errs) ->
560554
fprintf ppf "@[<v>@[<hv>%s:@;<1 2>%a@ %s@;<1 2>%a@]%a%a@]"
@@ -647,7 +641,7 @@ let context ppf cxt =
647641

648642
let include_err ppf (cxt, env, err) =
649643
Printtyp.wrap_printing_env env (fun () ->
650-
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)
651645

652646
let buffer = ref Bytes.empty
653647
let is_big obj =

0 commit comments

Comments
 (0)