@@ -674,7 +674,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
674
674
| Texp_constant cst -> Lconst (Const_base cst)
675
675
| Texp_let (rec_flag , pat_expr_list , body ) ->
676
676
transl_let rec_flag pat_expr_list (transl_exp body)
677
- | Texp_function {arg_label = _ ; param; case; partial} ->
677
+ | Texp_function {arg_label = _ ; arity; param; case; partial} -> (
678
678
let async = has_async_attribute e in
679
679
let directive =
680
680
match extract_directive_for_fn e with
@@ -695,7 +695,22 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
695
695
}
696
696
in
697
697
let loc = e.exp_loc in
698
- Lfunction {params; body; attr; loc}
698
+ let lambda = Lfunction {params; body; attr; loc} in
699
+ match arity with
700
+ | Some arity ->
701
+ let prim =
702
+ match (Ctype. expand_head e.exp_env e.exp_type).desc with
703
+ | Tarrow (Nolabel, t , _ , _ ) -> (
704
+ match (Ctype. expand_head e.exp_env t).desc with
705
+ | Tconstr (Pident {name = "unit" } , [] , _ ) -> Pjs_fn_make_unit
706
+ | _ -> Pjs_fn_make arity)
707
+ | _ -> Pjs_fn_make arity
708
+ in
709
+ Lprim
710
+ ( prim (* could be replaced with Opaque in the future except arity 0*) ,
711
+ [lambda],
712
+ loc )
713
+ | None -> lambda)
699
714
| Texp_apply
700
715
( ({
701
716
exp_desc = Texp_ident (_, _, {val_kind = Val_prim p});
@@ -781,27 +796,6 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
781
796
with Not_constant -> Lprim (Pmakeblock Blk_tuple , ll, e.exp_loc))
782
797
| Texp_construct ({txt = Lident "false" } , _ , [] ) -> Lconst Const_false
783
798
| Texp_construct ({txt = Lident "true" } , _ , [] ) -> Lconst Const_true
784
- | Texp_construct
785
- ({txt = Lident " Function$" }, _, [({exp_desc = Texp_function _} as expr)])
786
- ->
787
- (* ReScript uncurried encoding *)
788
- let loc = expr.exp_loc in
789
- let lambda = transl_exp expr in
790
- let arity =
791
- Ast_uncurried. uncurried_type_get_arity ~env: e.exp_env e.exp_type
792
- in
793
- let prim =
794
- match (Ctype. expand_head expr.exp_env expr.exp_type).desc with
795
- | Tarrow (Nolabel, t , _ , _ ) -> (
796
- match (Ctype. expand_head expr.exp_env t).desc with
797
- | Tconstr (Pident {name = "unit" } , [] , _ ) -> Pjs_fn_make_unit
798
- | _ -> Pjs_fn_make arity)
799
- | _ -> Pjs_fn_make arity
800
- in
801
- Lprim
802
- ( prim (* could be replaced with Opaque in the future except arity 0*) ,
803
- [lambda],
804
- loc )
805
799
| Texp_construct (lid , cstr , args ) -> (
806
800
let ll = transl_list args in
807
801
if cstr.cstr_inlined <> None then
0 commit comments