Skip to content

Commit 1e56f5f

Browse files
committed
Support type expansion in partial application.
1 parent 766a65f commit 1e56f5f

File tree

8 files changed

+44
-37
lines changed

8 files changed

+44
-37
lines changed

jscomp/build_tests/super_errors/fixtures/bucklescript.res

Lines changed: 0 additions & 4 deletions
This file was deleted.

jscomp/build_tests/super_errors/fixtures/uncurry_in_curry.res

Lines changed: 0 additions & 3 deletions
This file was deleted.

jscomp/ml/typecore.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,12 +2949,12 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
29492949
tvar || List.mem l ls
29502950
in
29512951
let ignored = ref [] in
2952-
let extract_uncurried t =
2953-
match t.desc with
2952+
let extract_uncurried_type t =
2953+
match (expand_head env t).desc with
29542954
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),[t],_) -> t
29552955
| _ -> t in
29562956
let lower_uncurried_arity ~nargs t newT =
2957-
match t.desc with
2957+
match (expand_head env t).desc with
29582958
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),a,_),[_],_) ->
29592959
let arity =
29602960
if String.sub a 0 5 = "arity"
@@ -3078,10 +3078,12 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
30783078
end;
30793079
([Nolabel, Some exp], ty_res)
30803080
| _ ->
3081-
let ty_ = funct.exp_type in
3082-
let ty = extract_uncurried ty_ in
3081+
let ty = extract_uncurried_type funct.exp_type in
30833082
let targs, ret_t = type_args [] [] ~ty_fun:ty (instance env ty) ~sargs in
3084-
targs, lower_uncurried_arity ty_ ~nargs:(List.length !ignored + List.length sargs) ret_t
3083+
let ret_t =
3084+
if funct.exp_type == ty then ret_t
3085+
else lower_uncurried_arity funct.exp_type ~nargs:(List.length !ignored + List.length sargs) ret_t in
3086+
targs, ret_t
30853087

30863088
and type_construct env loc lid sarg ty_expected attrs =
30873089
let opath =

jscomp/test/uncurried_cast.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function still2Args(param, param$1) {
6464
return withOpts(undefined, 4, param, param$1);
6565
}
6666

67-
var anInt = still2Args(3, 5);
67+
var anInt = Curry._1(still2Args, 3)(5);
6868

6969
var StandardNotation = {
7070
testRaise: testRaise,
@@ -118,7 +118,11 @@ function still2Args$1(param, param$1) {
118118
return withOpts$1(undefined, 4, param, param$1);
119119
}
120120

121-
var anInt$1 = still2Args$1(3, 5);
121+
var partial_arg$2 = 3;
122+
123+
var anInt$1 = (function (param) {
124+
return still2Args$1(partial_arg$2, param);
125+
})(5);
122126

123127
exports.Uncurried = Uncurried;
124128
exports.E = E;

jscomp/test/uncurried_cast.res

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ module StandardNotation = {
1818
let ll = partial((. x) => x + 1)
1919

2020
let withOpts = (. ~x=3, y, ~z=4, w) => x + y + z + w
21-
let still2Args : (. ~z: int=?, int) => int = withOpts(4)
22-
let anInt = still2Args(. ~z=3, 5)
21+
type unc2 = (. ~z: int=?, int) => int
22+
let still2Args : unc2 = withOpts(4)
23+
let anInt = still2Args(~z=3)(. 5)
2324
}
2425

2526
@@uncurried
@@ -33,5 +34,6 @@ let partial = List.map(. list{1, 2})
3334
let ll = partial(.x => x + 1)
3435

3536
let withOpts = (~x=3, y, ~z=4, w) => x + y + z + w
36-
let still2Args : (~z: int=?, int) => int = withOpts(. 4)
37-
let anInt = still2Args(~z=3, 5)
37+
type unc2 = (~z: int=?, int) => int
38+
let still2Args : unc2 = withOpts(. 4)
39+
let anInt = still2Args(. ~z=3)(5)

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43647,12 +43647,12 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
4364743647
tvar || List.mem l ls
4364843648
in
4364943649
let ignored = ref [] in
43650-
let extract_uncurried t =
43651-
match t.desc with
43650+
let extract_uncurried_type t =
43651+
match (expand_head env t).desc with
4365243652
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),[t],_) -> t
4365343653
| _ -> t in
4365443654
let lower_uncurried_arity ~nargs t newT =
43655-
match t.desc with
43655+
match (expand_head env t).desc with
4365643656
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),a,_),[_],_) ->
4365743657
let arity =
4365843658
if String.sub a 0 5 = "arity"
@@ -43776,10 +43776,12 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
4377643776
end;
4377743777
([Nolabel, Some exp], ty_res)
4377843778
| _ ->
43779-
let ty_ = funct.exp_type in
43780-
let ty = extract_uncurried ty_ in
43779+
let ty = extract_uncurried_type funct.exp_type in
4378143780
let targs, ret_t = type_args [] [] ~ty_fun:ty (instance env ty) ~sargs in
43782-
targs, lower_uncurried_arity ty_ ~nargs:(List.length !ignored + List.length sargs) ret_t
43781+
let ret_t =
43782+
if funct.exp_type == ty then ret_t
43783+
else lower_uncurried_arity funct.exp_type ~nargs:(List.length !ignored + List.length sargs) ret_t in
43784+
targs, ret_t
4378343785

4378443786
and type_construct env loc lid sarg ty_expected attrs =
4378543787
let opath =

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43647,12 +43647,12 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
4364743647
tvar || List.mem l ls
4364843648
in
4364943649
let ignored = ref [] in
43650-
let extract_uncurried t =
43651-
match t.desc with
43650+
let extract_uncurried_type t =
43651+
match (expand_head env t).desc with
4365243652
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),[t],_) -> t
4365343653
| _ -> t in
4365443654
let lower_uncurried_arity ~nargs t newT =
43655-
match t.desc with
43655+
match (expand_head env t).desc with
4365643656
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),a,_),[_],_) ->
4365743657
let arity =
4365843658
if String.sub a 0 5 = "arity"
@@ -43776,10 +43776,12 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
4377643776
end;
4377743777
([Nolabel, Some exp], ty_res)
4377843778
| _ ->
43779-
let ty_ = funct.exp_type in
43780-
let ty = extract_uncurried ty_ in
43779+
let ty = extract_uncurried_type funct.exp_type in
4378143780
let targs, ret_t = type_args [] [] ~ty_fun:ty (instance env ty) ~sargs in
43782-
targs, lower_uncurried_arity ty_ ~nargs:(List.length !ignored + List.length sargs) ret_t
43781+
let ret_t =
43782+
if funct.exp_type == ty then ret_t
43783+
else lower_uncurried_arity funct.exp_type ~nargs:(List.length !ignored + List.length sargs) ret_t in
43784+
targs, ret_t
4378343785

4378443786
and type_construct env loc lid sarg ty_expected attrs =
4378543787
let opath =

lib/4.06.1/whole_compiler.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98642,12 +98642,12 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
9864298642
tvar || List.mem l ls
9864398643
in
9864498644
let ignored = ref [] in
98645-
let extract_uncurried t =
98646-
match t.desc with
98645+
let extract_uncurried_type t =
98646+
match (expand_head env t).desc with
9864798647
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),[t],_) -> t
9864898648
| _ -> t in
9864998649
let lower_uncurried_arity ~nargs t newT =
98650-
match t.desc with
98650+
match (expand_head env t).desc with
9865198651
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),a,_),[_],_) ->
9865298652
let arity =
9865398653
if String.sub a 0 5 = "arity"
@@ -98771,10 +98771,12 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
9877198771
end;
9877298772
([Nolabel, Some exp], ty_res)
9877398773
| _ ->
98774-
let ty_ = funct.exp_type in
98775-
let ty = extract_uncurried ty_ in
98774+
let ty = extract_uncurried_type funct.exp_type in
9877698775
let targs, ret_t = type_args [] [] ~ty_fun:ty (instance env ty) ~sargs in
98777-
targs, lower_uncurried_arity ty_ ~nargs:(List.length !ignored + List.length sargs) ret_t
98776+
let ret_t =
98777+
if funct.exp_type == ty then ret_t
98778+
else lower_uncurried_arity funct.exp_type ~nargs:(List.length !ignored + List.length sargs) ret_t in
98779+
targs, ret_t
9877898780

9877998781
and type_construct env loc lid sarg ty_expected attrs =
9878098782
let opath =

0 commit comments

Comments
 (0)