Skip to content

Commit 477c7f8

Browse files
committed
Adapt error messages to new uncurried representation.
1 parent d5cb112 commit 477c7f8

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

jscomp/ml/typecore.ml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
21082108
| Lident "Uncurried$" ->
21092109
let arity = Ast_uncurried.attributes_to_arity sexp.pexp_attributes in
21102110
let uncurried_typ = Ast_uncurried.mk_js_fn ~env ~arity (newvar()) in
2111-
unify_exp_types loc env uncurried_typ ty_expected
2111+
unify_exp_types loc env ty_expected uncurried_typ
21122112
| _ -> ());
21132113
type_construct env loc lid sarg ty_expected sexp.pexp_attributes
21142114
| Pexp_variant(l, sarg) ->
@@ -3666,16 +3666,6 @@ let report_error env ppf = function
36663666
fprintf ppf "Variable %s must occur on both sides of this | pattern"
36673667
(Ident.name id);
36683668
spellcheck_idents ppf id valid_idents
3669-
| Expr_type_clash (
3670-
(_, {desc = Tarrow _}) ::
3671-
(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),_,_)}) :: _
3672-
) ->
3673-
fprintf ppf "This function is a curried function where an uncurried function is expected"
3674-
| Expr_type_clash (
3675-
(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),a,_),_,_)}) ::
3676-
(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),b,_),_,_)}) :: _
3677-
) when a <> b ->
3678-
fprintf ppf "This function has %s but was expected %s" a b
36793669
| Expr_type_clash (
36803670
(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js_OO"},"Meth",_),a,_),_,_)}) ::
36813671
(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js_OO"},"Meth",_),b,_),_,_)}) :: _

jscomp/super_errors/super_typecore.ml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ let print_expr_type_clash env trace ppf = begin
119119
show_extra_help ppf env trace;
120120
end
121121

122+
let reportArityMismatch ~arityA ~arityB ppf =
123+
fprintf ppf "This function expected @{<info>%s@} %s, but got @{<error>%s@}"
124+
arityA
125+
(if arityA = "1" then "argument" else "arguments")
126+
arityB
127+
122128
let reportJsFnArityMismatch ~arityA ~arityB ppf =
123129
let extractArity s =
124130
if Ext_string.starts_with s "arity" then
@@ -128,12 +134,9 @@ let reportJsFnArityMismatch ~arityA ~arityB ppf =
128134
else
129135
raise (Invalid_argument "Unrecognized arity type name.")
130136
in
131-
let firstNumber = extractArity arityA in
132-
fprintf ppf "This function expected @{<info>%s@} %s, but got @{<error>%s@}"
133-
firstNumber
134-
(if firstNumber = "1" then "argument" else "arguments")
135-
(extractArity arityB)
136-
137+
let arityA = extractArity arityA in
138+
let arityB = extractArity arityB in
139+
reportArityMismatch ~arityA ~arityB ppf
137140

138141
(* Pasted from typecore.ml. Needed for some cases in report_error below *)
139142
(* Records *)
@@ -177,13 +180,24 @@ let report_error env ppf = function
177180
| Expr_type_clash (
178181
(_, {desc = Tarrow _}) ::
179182
(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),_,_)}) :: _
180-
) ->
183+
)
184+
| Expr_type_clash (
185+
(_, {desc = Tarrow _}) ::
186+
(_, {desc = Tconstr (Pident {name = "uncurried$"},_,_)}) :: _
187+
) ->
181188
fprintf ppf "This function is a curried function where an uncurried function is expected"
182189
| Expr_type_clash (
183190
(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),arityA,_),_,_)}) ::
184191
(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),arityB,_),_,_)}) :: _
185192
) when arityA <> arityB ->
186193
reportJsFnArityMismatch ~arityA ~arityB ppf
194+
| Expr_type_clash (
195+
(_, {desc = Tconstr (Pident {name = "uncurried$"},[_; tA],_)}) ::
196+
(_, {desc = Tconstr (Pident {name = "uncurried$"},[_; tB],_)}) :: _
197+
) when Ast_uncurried.type_to_arity tA <> Ast_uncurried.type_to_arity tB ->
198+
let arityA = Ast_uncurried.type_to_arity tA |> string_of_int in
199+
let arityB = Ast_uncurried.type_to_arity tB |> string_of_int in
200+
reportArityMismatch ~arityA ~arityB ppf
187201
| Expr_type_clash (
188202
(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js_OO"},"Meth",_),a,_),_,_)}) ::
189203
(_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js_OO"},"Meth",_),b,_),_,_)}) :: _

res_syntax/src/res_outcome_printer.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ let rec printOutTypeDoc (outType : Outcometree.out_type) =
223223
when isArityIdent ident ->
224224
(* Js.Fn.arity2<(int, int) => int> -> (. int, int) => int*)
225225
printOutArrowType ~uncurried:true arrowType
226+
| Otyp_constr (Oide_ident "uncurried$", [(Otyp_arrow _ as arrowType); _arity])
227+
->
228+
(* uncurried$<(int, int) => int, [#2]> -> (. int, int) => int *)
229+
printOutArrowType ~uncurried:true arrowType
226230
| Otyp_constr (outIdent, []) -> printOutIdentDoc ~allowUident:false outIdent
227231
| Otyp_manifest (typ1, typ2) ->
228232
Doc.concat [printOutTypeDoc typ1; Doc.text " = "; printOutTypeDoc typ2]

0 commit comments

Comments
 (0)