Skip to content

Commit 386abea

Browse files
committed
Fix issue with uncurried function with 1 arg being a variable
Fixes #6504 Uncurried functions with 1 unit argument are emitted without the parameter. This leaves a possible undefined id in the emitted code if the parameter is a variable. This PR limits the optimization to cases where the parameter is explicitly `()`, as opposed to e.g. a variable whose type is inferred to be unit.
1 parent 363257e commit 386abea

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#### :bug: Bug Fix
2121
- Fix issue where an inline record with attributes did not parse. https://github.com/rescript-lang/rescript-compiler/pull/6499
22+
- Fix issue with uncurried function with 1 arg being a variable where an undefined variable could be emitted. https://github.com/rescript-lang/rescript-compiler/pull/6507
2223

2324
# 11.0.0-rc.6
2425

jscomp/core/lam_pass_alpha_conversion.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ let alpha_conversion (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
7171
| None -> Lam.prim ~primitive ~args:[ simpl arg ] loc)
7272
| Lprim { primitive = Pjs_fn_make_unit; args = [ arg ]; loc } ->
7373
let arg = match arg with
74-
| Lfunction ({arity=1; params=[x]; attr; body}) ->
74+
| Lfunction ({arity=1; params=[x]; attr; body}) when Ident.name x = "param" (* "()" *) ->
7575
Lam.function_ ~params:[x] ~attr:{attr with oneUnitArg=true} ~body ~arity:1
7676
| _ -> arg in
7777
simpl arg

jscomp/syntax/tests/printer/expr/Uncurried.res

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ let foo = (/* ddd */ x) => x
1111
let f = (
1212
// comment
1313
~a,
14-
) => a
14+
) => a
15+
16+
let fn = cb => {
17+
cb()
18+
}
19+
20+
fn(s => Js.log(#foo(s)))

0 commit comments

Comments
 (0)