Skip to content

Commit a35e183

Browse files
committed
Prepare to remove function$.
1 parent 92c6c75 commit a35e183

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

compiler/ml/ast_uncurried.ml

+5
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,8 @@ let uncurried_type_get_arity_opt ~env typ =
8686
match (Ctype.expand_head env typ).desc with
8787
| Tconstr (Pident {name = "function$"}, [t], _) -> Some (tarrow_to_arity t)
8888
| _ -> None
89+
90+
let remove_uncurried_type ~env typ =
91+
match (Ctype.expand_head env typ).desc with
92+
| Tconstr (Pident {name = "function$"}, [t], _) -> t
93+
| _ -> typ

compiler/ml/typecore.ml

+24-20
Original file line numberDiff line numberDiff line change
@@ -3527,34 +3527,38 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
35273527
tvar || List.mem l ls
35283528
in
35293529
let ignored = ref [] in
3530-
let has_uncurried_type funct =
3530+
let force_tvar =
35313531
let t = funct.exp_type in
35323532
match (expand_head env t).desc with
3533-
| Tconstr (Pident {name = "function$"}, [t], _) ->
3534-
let arity =
3535-
match Ast_uncurried.tarrow_to_arity_opt t with
3536-
| Some arity -> arity
3537-
| None -> List.length sargs
3538-
in
3539-
Some (arity, t)
3540-
| _ -> None
3533+
| Tvar _ when uncurried -> true
3534+
| _ -> false
3535+
in
3536+
let has_uncurried_type funct =
3537+
let t = funct.exp_type in
3538+
let inner_t = Ast_uncurried.remove_uncurried_type ~env t in
3539+
if force_tvar then Some (List.length sargs, inner_t)
3540+
else
3541+
match (Ctype.repr inner_t).desc with
3542+
| Tarrow (_, _, _, _, Some arity) -> Some (arity, inner_t)
3543+
| _ -> None
35413544
in
35423545
let force_uncurried_type funct =
3543-
match has_uncurried_type funct with
3544-
| None -> (
3546+
if force_tvar then
35453547
let arity = List.length sargs in
35463548
let uncurried_typ =
35473549
Ast_uncurried.make_uncurried_type ~env ~arity (newvar ())
35483550
in
3549-
match (expand_head env funct.exp_type).desc with
3550-
| Tvar _ | Tarrow _ -> unify_exp env funct uncurried_typ
3551-
| _ ->
3552-
raise
3553-
(Error
3554-
( funct.exp_loc,
3555-
env,
3556-
Apply_non_function (expand_head env funct.exp_type) )))
3557-
| Some _ -> ()
3551+
unify_exp env funct uncurried_typ
3552+
else if
3553+
Ast_uncurried.tarrow_to_arity_opt
3554+
(Ast_uncurried.remove_uncurried_type ~env funct.exp_type)
3555+
= None
3556+
then
3557+
raise
3558+
(Error
3559+
( funct.exp_loc,
3560+
env,
3561+
Apply_non_function (expand_head env funct.exp_type) ))
35583562
in
35593563
let extract_uncurried_type funct =
35603564
let t = funct.exp_type in

tests/tools_tests/src/expected/TestPpx.res.jsout

-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ async function fpromise(promise, _x) {
4141

4242
let Uncurried = {};
4343

44-
let Uncurried = {};
45-
4644
let a = "A";
4745

4846
let b = "B";

0 commit comments

Comments
 (0)