@@ -3527,34 +3527,38 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
3527
3527
tvar || List. mem l ls
3528
3528
in
3529
3529
let ignored = ref [] in
3530
- let has_uncurried_type funct =
3530
+ let force_tvar =
3531
3531
let t = funct.exp_type in
3532
3532
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
3541
3544
in
3542
3545
let force_uncurried_type funct =
3543
- match has_uncurried_type funct with
3544
- | None -> (
3546
+ if force_tvar then
3545
3547
let arity = List. length sargs in
3546
3548
let uncurried_typ =
3547
3549
Ast_uncurried. make_uncurried_type ~env ~arity (newvar () )
3548
3550
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) ))
3558
3562
in
3559
3563
let extract_uncurried_type funct =
3560
3564
let t = funct.exp_type in
0 commit comments