@@ -315,8 +315,6 @@ let unify_pat_types loc env ty ty' =
315
315
316
316
(* unification inside type_exp and type_expect *)
317
317
let unify_exp_types ?type_clash_context loc env ty expected_ty =
318
- (* Format.eprintf "@[%a@ %a@]@." Printtyp.raw_type_expr exp.exp_type
319
- Printtyp.raw_type_expr expected_ty; *)
320
318
try unify env ty expected_ty with
321
319
| Unify trace ->
322
320
raise (Error (loc, env, Expr_type_clash (trace, type_clash_context)))
@@ -3268,7 +3266,7 @@ and type_function ?in_function ~arity loc attrs env ty_expected_ l caselist =
3268
3266
match arity with
3269
3267
| None -> ty_expected_
3270
3268
| Some arity ->
3271
- let fun_t = newvar () in
3269
+ let fun_t = newty ( Tarrow (l, newvar () , newvar () , Cok , Some arity) ) in
3272
3270
let uncurried_typ = Ast_uncurried. make_uncurried_type ~env ~arity fun_t in
3273
3271
unify_exp_types loc env uncurried_typ ty_expected_;
3274
3272
fun_t
@@ -3519,7 +3517,6 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
3519
3517
3520
3518
and type_application ?type_clash_context uncurried env funct (sargs : sargs ) :
3521
3519
targs * Types. type_expr * bool =
3522
- (* funct.exp_type may be generic *)
3523
3520
let result_type omitted ty_fun =
3524
3521
List. fold_left
3525
3522
(fun ty_fun (l , ty , lv ) -> newty2 lv (Tarrow (l, ty, ty_fun, Cok , None )))
@@ -3530,15 +3527,20 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
3530
3527
tvar || List. mem l ls
3531
3528
in
3532
3529
let ignored = ref [] in
3533
- let has_uncurried_type t =
3530
+ let has_uncurried_type funct =
3531
+ let t = funct.exp_type in
3534
3532
match (expand_head env t).desc with
3535
- | Tconstr (Pident {name = "function$" } , [t ; t_arity ], _ ) ->
3536
- let arity = Ast_uncurried. type_to_arity t_arity in
3533
+ | Tconstr (Pident {name = "function$" } , [t ; _t_arity ], _ ) ->
3534
+ let arity =
3535
+ match Ast_uncurried. tarrow_to_arity_opt t with
3536
+ | Some arity -> arity
3537
+ | None -> List. length sargs
3538
+ in
3537
3539
Some (arity, t)
3538
3540
| _ -> None
3539
3541
in
3540
3542
let force_uncurried_type funct =
3541
- match has_uncurried_type funct.exp_type with
3543
+ match has_uncurried_type funct with
3542
3544
| None -> (
3543
3545
let arity = List. length sargs in
3544
3546
let uncurried_typ =
@@ -3554,8 +3556,9 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
3554
3556
Apply_non_function (expand_head env funct.exp_type) )))
3555
3557
| Some _ -> ()
3556
3558
in
3557
- let extract_uncurried_type t =
3558
- match has_uncurried_type t with
3559
+ let extract_uncurried_type funct =
3560
+ let t = funct.exp_type in
3561
+ match has_uncurried_type funct with
3559
3562
| Some (arity , t1 ) ->
3560
3563
if List. length sargs > arity then
3561
3564
raise
@@ -3566,8 +3569,8 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
3566
3569
(t1, arity)
3567
3570
| None -> (t, max_int)
3568
3571
in
3569
- let update_uncurried_arity ~nargs t new_t =
3570
- match has_uncurried_type t with
3572
+ let update_uncurried_arity ~nargs funct new_t =
3573
+ match has_uncurried_type funct with
3571
3574
| Some (arity , _ ) ->
3572
3575
let newarity = arity - nargs in
3573
3576
let fully_applied = newarity < = 0 in
@@ -3576,7 +3579,8 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
3576
3579
(Error
3577
3580
( funct.exp_loc,
3578
3581
env,
3579
- Uncurried_arity_mismatch (t, arity, List. length sargs) ));
3582
+ Uncurried_arity_mismatch
3583
+ (funct.exp_type, arity, List. length sargs) ));
3580
3584
let new_t =
3581
3585
if fully_applied then new_t
3582
3586
else Ast_uncurried. make_uncurried_type ~env ~arity: newarity new_t
@@ -3721,7 +3725,7 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
3721
3725
(Ext_list. filter labels (fun x -> x <> Nolabel ))) ))
3722
3726
in
3723
3727
if uncurried then force_uncurried_type funct;
3724
- let ty, max_arity = extract_uncurried_type funct.exp_type in
3728
+ let ty, max_arity = extract_uncurried_type funct in
3725
3729
let top_arity = if uncurried then Some max_arity else None in
3726
3730
match sargs with
3727
3731
(* Special case for ignore : avoid discarding warning * )
@@ -3744,7 +3748,7 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
3744
3748
~sargs ~top_arity
3745
3749
in
3746
3750
let fully_applied, ret_t =
3747
- update_uncurried_arity funct.exp_type
3751
+ update_uncurried_arity funct
3748
3752
~nargs: (List. length ! ignored + List. length sargs)
3749
3753
ret_t
3750
3754
in
@@ -4340,13 +4344,27 @@ let report_error env ppf = function
4340
4344
" This function is an uncurried function where a curried function is \
4341
4345
expected"
4342
4346
| Expr_type_clash
4343
- ( (_, {desc = Tconstr (Pident {name = " function$" }, [_; t_a], _)})
4344
- :: (_, {desc = Tconstr (Pident {name = " function$" }, [_; t_b], _)})
4347
+ ( ( _,
4348
+ {
4349
+ desc =
4350
+ Tconstr
4351
+ ( Pident {name = " function$" },
4352
+ [{desc = Tarrow (_, _, _, _, Some arity_a)}; _],
4353
+ _ );
4354
+ } )
4355
+ :: ( _,
4356
+ {
4357
+ desc =
4358
+ Tconstr
4359
+ ( Pident {name = " function$" },
4360
+ [{desc = Tarrow (_, _, _, _, Some arity_b)}; _],
4361
+ _ );
4362
+ } )
4345
4363
:: _,
4346
4364
_ )
4347
- when Ast_uncurried. type_to_arity t_a <> Ast_uncurried. type_to_arity t_b ->
4348
- let arity_a = Ast_uncurried. type_to_arity t_a |> string_of_int in
4349
- let arity_b = Ast_uncurried. type_to_arity t_b |> string_of_int in
4365
+ when arity_a <> arity_b ->
4366
+ let arity_a = arity_a |> string_of_int in
4367
+ let arity_b = arity_b |> string_of_int in
4350
4368
report_arity_mismatch ~arity_a ~arity_b ppf
4351
4369
| Expr_type_clash
4352
4370
( ( _,
0 commit comments