Skip to content

Commit 436c010

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 436c010

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-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/test/UncurriedAlways.js

+24-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/UncurriedAlways.res

+10
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,13 @@ module OptMixed = {
6565
let c3 = ptl(~x="x", ~z="z", ~d2="d2<-200", ~d4="d4<-400")
6666
Js.log2("c3:", c3)
6767
}
68+
69+
let fn = cb => {
70+
cb()
71+
}
72+
73+
fn(s => Js.log(#foo(s)))
74+
75+
let fn1 = (a, b, ()) => a() + b
76+
77+
let a = fn1(() => 1, 2, _)

0 commit comments

Comments
 (0)