Skip to content

Commit d314f94

Browse files
committed
Disable Unerasable_optional_argument for uncurried functions via the type checker.
In reality this disables also the check for the body, but this check is on the way out so this should be reasonable in practice without over-complicating the error logic.
1 parent 383a64d commit d314f94

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

jscomp/ml/typecore.ml

+11-6
Original file line numberDiff line numberDiff line change
@@ -2103,13 +2103,18 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
21032103
exp_type = newty (Ttuple (List.map (fun e -> e.exp_type) expl));
21042104
exp_attributes = sexp.pexp_attributes;
21052105
exp_env = env }
2106+
| Pexp_construct({txt = Lident "Function$"} as lid, sarg) ->
2107+
let state = Warnings.backup () in
2108+
let arity = Ast_uncurried.attributes_to_arity sexp.pexp_attributes in
2109+
let uncurried_typ = Ast_uncurried.make_uncurried_type ~env ~arity (newvar()) in
2110+
unify_exp_types loc env ty_expected uncurried_typ;
2111+
(* Disable Unerasable_optional_argument for uncurried functions *)
2112+
let unerasable_optional_argument = Warnings.number Unerasable_optional_argument in
2113+
Warnings.parse_options false ("-" ^ string_of_int unerasable_optional_argument);
2114+
let exp = type_construct env loc lid sarg ty_expected sexp.pexp_attributes in
2115+
Warnings.restore state;
2116+
exp
21062117
| Pexp_construct(lid, sarg) ->
2107-
(match lid.txt with
2108-
| Lident "Function$" ->
2109-
let arity = Ast_uncurried.attributes_to_arity sexp.pexp_attributes in
2110-
let uncurried_typ = Ast_uncurried.make_uncurried_type ~env ~arity (newvar()) in
2111-
unify_exp_types loc env ty_expected uncurried_typ
2112-
| _ -> ());
21132118
type_construct env loc lid sarg ty_expected sexp.pexp_attributes
21142119
| Pexp_variant(l, sarg) ->
21152120
(* Keep sharing *)

jscomp/test/uncurried_default.args.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ let total = withOpt(~x=10, 3)(~z=4, 11)
1717
let foo1 = (~x=3, ~y) => x+y
1818
let r1 = foo1(~y=11)
1919

20-
let foo2 = @warning("-16") (~y, ~x=3, ~z=4) => x+y+z
20+
let foo2 = (~y, ~x=3, ~z=4) => x+y+z
2121
let r2 = foo2(~y=11)

0 commit comments

Comments
 (0)