@@ -1913,9 +1913,12 @@ let rec approx_type env sty =
1913
1913
let rec type_approx env sexp =
1914
1914
match sexp.pexp_desc with
1915
1915
| Pexp_let (_ , _ , e ) -> type_approx env e
1916
- | Pexp_fun (p , _ , _ , e , _arity ) ->
1916
+ | Pexp_fun (p , _ , _ , e , arity ) -> (
1917
1917
let ty = if is_optional p then type_option (newvar () ) else newvar () in
1918
- newty (Tarrow (p, ty, type_approx env e, Cok ))
1918
+ let t = newty (Tarrow (p, ty, type_approx env e, Cok )) in
1919
+ match arity with
1920
+ | None -> t
1921
+ | Some arity -> Ast_uncurried. make_uncurried_type ~env ~arity t)
1919
1922
| Pexp_match (_ , {pc_rhs = e } :: _ ) -> type_approx env e
1920
1923
| Pexp_try (e , _ ) -> type_approx env e
1921
1924
| Pexp_tuple l -> newty (Ttuple (List. map (type_approx env) l))
@@ -2525,25 +2528,6 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
2525
2528
exp_attributes = sexp.pexp_attributes;
2526
2529
exp_env = env;
2527
2530
}
2528
- | Pexp_construct
2529
- ( ({txt = Lident " Function$" } as lid),
2530
- (Some {pexp_desc = Pexp_fun (_, _, _, _, Some arity)} as sarg) ) ->
2531
- let state = Warnings. backup () in
2532
- let uncurried_typ =
2533
- Ast_uncurried. make_uncurried_type ~env ~arity (newvar () )
2534
- in
2535
- unify_exp_types loc env uncurried_typ ty_expected;
2536
- (* Disable Unerasable_optional_argument for uncurried functions *)
2537
- let unerasable_optional_argument =
2538
- Warnings. number Unerasable_optional_argument
2539
- in
2540
- Warnings. parse_options false
2541
- (" -" ^ string_of_int unerasable_optional_argument);
2542
- let exp =
2543
- type_construct env loc lid sarg uncurried_typ sexp.pexp_attributes
2544
- in
2545
- Warnings. restore state;
2546
- exp
2547
2531
| Pexp_construct (lid , sarg ) ->
2548
2532
type_construct env loc lid sarg ty_expected sexp.pexp_attributes
2549
2533
| Pexp_variant (l , sarg ) -> (
@@ -3273,7 +3257,22 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
3273
3257
| Pexp_extension ext ->
3274
3258
raise (Error_forward (Builtin_attributes. error_of_extension ext))
3275
3259
3276
- and type_function ?in_function ~arity loc attrs env ty_expected l caselist =
3260
+ and type_function ?in_function ~arity loc attrs env ty_expected_ l caselist =
3261
+ let state = Warnings. backup () in
3262
+ (* Disable Unerasable_optional_argument for uncurried functions *)
3263
+ let unerasable_optional_argument =
3264
+ Warnings. number Unerasable_optional_argument
3265
+ in
3266
+ Warnings. parse_options false (" -" ^ string_of_int unerasable_optional_argument);
3267
+ let ty_expected =
3268
+ match arity with
3269
+ | None -> ty_expected_
3270
+ | Some arity ->
3271
+ let fun_t = newvar () in
3272
+ let uncurried_typ = Ast_uncurried. make_uncurried_type ~env ~arity fun_t in
3273
+ unify_exp_types loc env uncurried_typ ty_expected_;
3274
+ fun_t
3275
+ in
3277
3276
let loc_fun, ty_fun =
3278
3277
match in_function with
3279
3278
| Some p -> p
@@ -3311,12 +3310,19 @@ and type_function ?in_function ~arity loc attrs env ty_expected l caselist =
3311
3310
Location. prerr_warning case.c_lhs.pat_loc
3312
3311
Warnings. Unerasable_optional_argument ;
3313
3312
let param = name_pattern " param" cases in
3313
+ let exp_type = instance env (newgenty (Tarrow (l, ty_arg, ty_res, Cok ))) in
3314
+ let exp_type =
3315
+ match arity with
3316
+ | None -> exp_type
3317
+ | Some arity -> Ast_uncurried. make_uncurried_type ~env ~arity exp_type
3318
+ in
3319
+ Warnings. restore state;
3314
3320
re
3315
3321
{
3316
3322
exp_desc = Texp_function {arg_label = l; arity; param; case; partial};
3317
3323
exp_loc = loc;
3318
3324
exp_extra = [] ;
3319
- exp_type = instance env (newgenty ( Tarrow (l, ty_arg, ty_res, Cok ))) ;
3325
+ exp_type;
3320
3326
exp_attributes = attrs;
3321
3327
exp_env = env;
3322
3328
}
0 commit comments