@@ -315,8 +315,6 @@ let unify_pat_types loc env ty ty' =
315315
316316(* unification inside type_exp and type_expect *)
317317let 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; *)
320318 try unify env ty expected_ty with
321319 | Unify trace ->
322320 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 =
32683266 match arity with
32693267 | None -> ty_expected_
32703268 | Some arity ->
3271- let fun_t = newvar () in
3269+ let fun_t = newty ( Tarrow (l, newvar () , newvar () , Cok , Some arity) ) in
32723270 let uncurried_typ = Ast_uncurried. make_uncurried_type ~env ~arity fun_t in
32733271 unify_exp_types loc env uncurried_typ ty_expected_;
32743272 fun_t
@@ -3519,7 +3517,6 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
35193517
35203518and type_application ?type_clash_context uncurried env funct (sargs : sargs ) :
35213519 targs * Types. type_expr * bool =
3522- (* funct.exp_type may be generic *)
35233520 let result_type omitted ty_fun =
35243521 List. fold_left
35253522 (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) :
35303527 tvar || List. mem l ls
35313528 in
35323529 let ignored = ref [] in
3533- let has_uncurried_type t =
3530+ let has_uncurried_type funct =
3531+ let t = funct.exp_type in
35343532 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
35373539 Some (arity, t)
35383540 | _ -> None
35393541 in
35403542 let force_uncurried_type funct =
3541- match has_uncurried_type funct.exp_type with
3543+ match has_uncurried_type funct with
35423544 | None -> (
35433545 let arity = List. length sargs in
35443546 let uncurried_typ =
@@ -3554,8 +3556,9 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
35543556 Apply_non_function (expand_head env funct.exp_type) )))
35553557 | Some _ -> ()
35563558 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
35593562 | Some (arity , t1 ) ->
35603563 if List. length sargs > arity then
35613564 raise
@@ -3566,8 +3569,8 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
35663569 (t1, arity)
35673570 | None -> (t, max_int)
35683571 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
35713574 | Some (arity , _ ) ->
35723575 let newarity = arity - nargs in
35733576 let fully_applied = newarity < = 0 in
@@ -3576,7 +3579,8 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
35763579 (Error
35773580 ( funct.exp_loc,
35783581 env,
3579- Uncurried_arity_mismatch (t, arity, List. length sargs) ));
3582+ Uncurried_arity_mismatch
3583+ (funct.exp_type, arity, List. length sargs) ));
35803584 let new_t =
35813585 if fully_applied then new_t
35823586 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) :
37213725 (Ext_list. filter labels (fun x -> x <> Nolabel ))) ))
37223726 in
37233727 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
37253729 let top_arity = if uncurried then Some max_arity else None in
37263730 match sargs with
37273731 (* Special case for ignore : avoid discarding warning * )
@@ -3744,7 +3748,7 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
37443748 ~sargs ~top_arity
37453749 in
37463750 let fully_applied, ret_t =
3747- update_uncurried_arity funct.exp_type
3751+ update_uncurried_arity funct
37483752 ~nargs: (List. length ! ignored + List. length sargs)
37493753 ret_t
37503754 in
@@ -4340,13 +4344,27 @@ let report_error env ppf = function
43404344 " This function is an uncurried function where a curried function is \
43414345 expected"
43424346 | 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+ } )
43454363 :: _,
43464364 _ )
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
43504368 report_arity_mismatch ~arity_a ~arity_b ppf
43514369 | Expr_type_clash
43524370 ( ( _,
0 commit comments