Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#### :bug: Bug fix

- Fix partial application generalization for `...`. https://github.com/rescript-lang/rescript/pull/8343

#### :memo: Documentation

#### :nail_care: Polish
Expand Down
5 changes: 5 additions & 0 deletions compiler/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,11 @@ let rec is_nonexpansive exp =
List.for_all (fun vb -> is_nonexpansive vb.vb_expr) pat_exp_list
&& is_nonexpansive body
| Texp_function _ -> true
| Texp_apply {partial = true; _} ->
(* ReScript partial applications (`foo(args, ...)`) lower to wrapper
functions in codegen, so creating the partial itself is nonexpansive
like an explicit lambda. *)
true
| Texp_apply {funct = e; args = (_, None) :: el} ->
is_nonexpansive e && List.for_all is_nonexpansive_opt (List.map snd el)
| Texp_match (e, cases, [], _) ->
Expand Down
11 changes: 10 additions & 1 deletion tests/tests/src/PartialApplicationNoRuntimeCurry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ function add5(extra) {
return 5 + extra | 0;
}

function addHookPartial(extra) {
addHook(hook, extra);
}

addHook(hook, _x => {});

addHook(hook, _x => {});

export {
f,
add$1 as add,
add5,
addHookPartial,
}
/* No side effect */
/* Not a pure module */
8 changes: 8 additions & 0 deletions tests/tests/src/PartialApplicationNoRuntimeCurry.res
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ let f = u => {
type fn2 = (int, int) => int
let add: fn2 = (a, b) => a + b
let add5: int => int = add(5, ...)

type hook
external hook: hook = "hook"
external addHook: (hook, 'a => unit) => unit = "addHook"

let addHookPartial = addHook(hook, ...)
let _ = addHookPartial((_x: int) => ())
let _ = addHookPartial((_x: string) => ())
Loading