Skip to content

Commit c204fc9

Browse files
committed
Fix issue in partial application when the last named arg is provided.
Fix the check to determine whether all the arguments were passed to a partial application. The check needs to keep into account the real arguments passed. Fixes #6680
1 parent 49212ab commit c204fc9

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

jscomp/ml/translcore.ml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,18 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
763763
Translattribute.get_and_remove_inlined_attribute funct
764764
in
765765
let uncurried_partial_application =
766+
(* In case of partial application foo(args, ...) when some args are missing,
767+
get the arity *)
766768
let uncurried_partial_app = Ext_list.exists e.exp_attributes (fun ({txt },_) -> txt = "res.partial") in
767769
if uncurried_partial_app then
768-
let arity_opt = Ast_uncurried.uncurried_type_get_arity_opt ~env:funct.exp_env funct.exp_type in
769-
arity_opt
770+
let arity_opt = Ast_uncurried.uncurried_type_get_arity_opt ~env:funct.exp_env funct.exp_type in
771+
match arity_opt with
772+
| Some arity ->
773+
let real_args = List.filter (fun (_, x) -> Option.is_some x) oargs in
774+
if arity > List.length real_args then
775+
Some arity
776+
else None
777+
| None -> None
770778
else
771779
None in
772780
transl_apply ~inlined ~uncurried_partial_application (transl_exp funct) oargs e.exp_loc
@@ -1036,7 +1044,7 @@ and transl_apply ?(inlined = Default_inline) ?(uncurried_partial_application=Non
10361044
| [] -> lapply lam (List.rev_map fst args)
10371045
in
10381046
match uncurried_partial_application with
1039-
| Some arity when arity > List.length sargs ->
1047+
| Some arity ->
10401048
let extra_arity = arity - List.length sargs in
10411049
let none_ids = ref [] in
10421050
let args = Ext_list.filter_map sargs (function

jscomp/test/UncurriedAlways.js

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/UncurriedAlways.res

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,18 @@ fn(s => Js.log(#foo(s)))
7575
let fn1 = (a, b, ()) => a() + b
7676

7777
let a = fn1(() => 1, 2, _)
78+
79+
module PartialApplication = {
80+
let f3 = (~x, ~y, ~z) => {
81+
Js.log(x)
82+
x + y + z
83+
}
84+
85+
let fx = f3(~x=1, ...)
86+
87+
let fy = f3(~y=1, ...)
88+
89+
let fz = f3(~z=1, ...)
90+
91+
let fxyz = f3(~x=1, ~y=1, ~z=1, ...)
92+
}

0 commit comments

Comments
 (0)