Skip to content

Commit 889c2d8

Browse files
committed
Fix super error mishandling uncurried function
1 parent c03abaa commit 889c2d8

11 files changed

+44
-9
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/UncurriedArgsNotApplied.res:3:15-21
4+
5+
1 │ let apply = (fn: (. unit) => option<int>) => fn(. ())
6+
2 │
7+
3 │ let _ = apply(Some(1))
8+
4 │
9+
10+
This value might need to be wrapped in a function that takes an extra
11+
parameter of type unit
12+
13+
Here's the original error message
14+
This has type: option<'a>
15+
But it's expected to have type: (. unit) => option<int>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let apply = (fn: (. unit) => option<int>) => fn(. ())
2+
3+
let _ = apply(Some(1))

jscomp/frontend/ast_core_type.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ let get_uncurry_arity (ty : t) =
126126

127127
let get_curry_arity (ty : t) =
128128
if Ast_uncurried.coreTypeIsUncurriedFun ty then
129-
let arity, _ = Ast_uncurried.typeExtractUncurriedFun ty in
129+
let arity, _ = Ast_uncurried.coreTypeExtractUncurriedFun ty in
130130
arity
131131
else get_uncurry_arity_aux ty 0
132132

jscomp/frontend/ast_external_process.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ let spec_of_ptyp (nolabel : bool) (ptyp : Parsetree.core_type) :
6969
| `Uncurry opt_arity -> (
7070
let real_arity =
7171
if Ast_uncurried.coreTypeIsUncurriedFun ptyp then
72-
let arity, _ = Ast_uncurried.typeExtractUncurriedFun ptyp in
72+
let arity, _ = Ast_uncurried.coreTypeExtractUncurriedFun ptyp in
7373
Some arity
7474
else Ast_core_type.get_uncurry_arity ptyp
7575
in

jscomp/ml/ast_uncurried.ml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,20 @@ let coreTypeIsUncurriedFun (typ : Parsetree.core_type) =
6969
true
7070
| _ -> false
7171

72-
let typeIsUncurriedFun = Ast_uncurried_utils.typeIsUncurriedFun
73-
74-
let typeExtractUncurriedFun (typ : Parsetree.core_type) =
72+
let coreTypeExtractUncurriedFun (typ : Parsetree.core_type) =
7573
match typ.ptyp_desc with
7674
| Ptyp_constr ({txt = Lident "function$"}, [tArg; tArity]) ->
7775
(arityFromType tArity, tArg)
7876
| _ -> assert false
7977

78+
let typeIsUncurriedFun = Ast_uncurried_utils.typeIsUncurriedFun
79+
80+
let typeExtractUncurriedFun (typ : Types.type_expr) =
81+
match typ.desc with
82+
| Tconstr (Pident {name = "function$"}, [tArg; _], _) ->
83+
tArg
84+
| _ -> assert false
85+
8086
(* Typed AST *)
8187

8288
let arity_to_type arity =
@@ -114,3 +120,6 @@ let uncurried_type_get_arity_opt ~env typ =
114120
| Tconstr (Pident { name = "function$" }, [ _t; tArity ], _) ->
115121
Some (type_to_arity tArity)
116122
| _ -> None
123+
124+
125+

jscomp/ml/error_message_utils.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ let typeClashContextMaybeOption ty_expected ty_res =
204204
| ( {Types.desc = Tconstr (expectedPath, _, _)},
205205
{Types.desc = Tconstr (typePath, _, _)} )
206206
when Path.same Predef.path_option typePath
207-
&& Path.same expectedPath Predef.path_option = false ->
207+
&& Path.same expectedPath Predef.path_option = false
208+
&& Path.same expectedPath Predef.path_uncurried = false ->
208209
Some MaybeUnwrapOption
209210
| _ -> None
210211

jscomp/ml/predef.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ and path_extension_constructor = Pident ident_extension_constructor
9595
and path_floatarray = Pident ident_floatarray
9696

9797
and path_promise = Pident ident_promise
98+
and path_uncurried = Pident ident_uncurried
9899

99100
let type_int = newgenty (Tconstr(path_int, [], ref Mnil))
100101
and type_char = newgenty (Tconstr(path_char, [], ref Mnil))

jscomp/ml/predef.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ val path_lazy_t: Path.t
5555
val path_extension_constructor: Path.t
5656
val path_floatarray: Path.t
5757
val path_promise: Path.t
58+
val path_uncurried: Path.t
5859

5960
val path_match_failure: Path.t
6061
val path_assert_failure : Path.t

jscomp/ml/typecore.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ let extract_concrete_record env ty =
307307

308308
let extract_concrete_variant env ty =
309309
match extract_concrete_typedecl env ty with
310-
(p0, p, {type_kind=Type_variant cstrs}) -> (p0, p, cstrs)
310+
(p0, p, {type_kind=Type_variant cstrs})
311+
when not (Ast_uncurried.typeIsUncurriedFun ty)
312+
-> (p0, p, cstrs)
311313
| (p0, p, {type_kind=Type_open}) -> (p0, p, [])
312314
| _ -> raise Not_found
313315

@@ -662,6 +664,9 @@ let rec collect_missing_arguments env type1 type2 = match type1 with
662664
| Some res -> Some ((label, argtype) :: res)
663665
| None -> None
664666
end
667+
| t when Ast_uncurried_utils.typeIsUncurriedFun t ->
668+
let typ = Ast_uncurried.typeExtractUncurriedFun t in
669+
collect_missing_arguments env typ type2
665670
| _ -> None
666671

667672
let print_expr_type_clash ?typeClashContext env trace ppf = begin

jscomp/syntax/src/jsx_common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let optionalAttr = ({txt = "res.optional"; loc = Location.none}, PStr [])
4949

5050
let extractUncurried typ =
5151
if Ast_uncurried.coreTypeIsUncurriedFun typ then
52-
let _arity, t = Ast_uncurried.typeExtractUncurriedFun typ in
52+
let _arity, t = Ast_uncurried.coreTypeExtractUncurriedFun typ in
5353
t
5454
else typ
5555

jscomp/syntax/src/res_printer.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl =
16711671
printObject ~state ~inline:false fields openFlag cmtTbl
16721672
| Ptyp_arrow _ -> printArrow ~uncurried:false typExpr
16731673
| Ptyp_constr _ when Ast_uncurried.coreTypeIsUncurriedFun typExpr ->
1674-
let arity, tArg = Ast_uncurried.typeExtractUncurriedFun typExpr in
1674+
let arity, tArg = Ast_uncurried.coreTypeExtractUncurriedFun typExpr in
16751675
printArrow ~uncurried:true ~arity tArg
16761676
| Ptyp_constr (longidentLoc, [{ptyp_desc = Ptyp_object (fields, openFlag)}])
16771677
->

0 commit comments

Comments
 (0)