Skip to content

Commit 7d93780

Browse files
committed
Fix underscore in uncurried mode.
1 parent a2af63c commit 7d93780

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ These are only breaking changes for unformatted code.
5757
- Fix issue with error messages for uncurried functions where expected and given type were swapped https://github.com/rescript-lang/rescript-compiler/pull/5973
5858
- Fix issue with integer overflow check https://github.com/rescript-lang/rescript-compiler/pull/6028
5959
- Make internal encoding of locations aware of unicode https://github.com/rescript-lang/rescript-compiler/pull/6073
60+
- Fix issue where `foo(x,_)` in uncurried mode would generate a curried function https://github.com/rescript-lang/rescript-compiler/pull/6082
6061

6162
#### :nail_care: Polish
6263

jscomp/test/UncurriedAlways.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,31 @@ function ptl(param) {
2727
return foo(10, param);
2828
}
2929

30+
function foo2(x, y) {
31+
return x + y | 0;
32+
}
33+
34+
function bar2(__x) {
35+
return __x + 3 | 0;
36+
}
37+
38+
function foo3(x, y, z) {
39+
return (x + y | 0) + z | 0;
40+
}
41+
42+
function bar3(__x) {
43+
return foo3(__x, 3, 4);
44+
}
45+
3046
exports.foo = foo;
3147
exports.z = z;
3248
exports.bar = bar;
3349
exports.b = b;
3450
exports.w = w;
3551
exports.a = a;
3652
exports.ptl = ptl;
53+
exports.foo2 = foo2;
54+
exports.bar2 = bar2;
55+
exports.foo3 = foo3;
56+
exports.bar3 = bar3;
3757
/* Not a pure module */

jscomp/test/UncurriedAlways.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ Js.log(a) // Test automatic uncurried application
1717
let _ = Js.Array2.map([1], (. x) => x+1)
1818

1919
let ptl = @res.partial foo(10) // force partial application
20+
21+
let foo2 = (x,y) => x+y
22+
let bar2: _ => _ = foo2(_, 3)
23+
24+
let foo3 = (x,y,z) => x+y+z
25+
let bar3 : _ => _ = foo3(_, 3, 4)

res_syntax/src/res_core.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ let wrapTypeAnnotation ~loc newtypes core_type body =
516516
* return a wrapping function that wraps ((__x) => ...) around an expression
517517
* e.g. foo(_, 3) becomes (__x) => foo(__x, 3)
518518
*)
519-
let processUnderscoreApplication args =
519+
let processUnderscoreApplication (p : Parser.t) args =
520520
let exp_question = ref None in
521521
let hidden_var = "__x" in
522522
let check_arg ((lab, exp) as arg) =
@@ -537,7 +537,9 @@ let processUnderscoreApplication args =
537537
(Ppat_var (Location.mkloc hidden_var loc))
538538
~loc:Location.none
539539
in
540-
Ast_helper.Exp.mk (Pexp_fun (Nolabel, None, pattern, exp_apply)) ~loc
540+
let funExpr = Ast_helper.Exp.fun_ ~loc Nolabel None pattern exp_apply in
541+
if p.uncurried_config = Legacy then funExpr
542+
else Ast_uncurried.uncurriedFun ~loc ~arity:1 funExpr
541543
| None -> exp_apply
542544
in
543545
(args, wrap)
@@ -3667,7 +3669,7 @@ and parseCallExpr p funExpr =
36673669
List.fold_left
36683670
(fun callBody group ->
36693671
let dotted, args = group in
3670-
let args, wrap = processUnderscoreApplication args in
3672+
let args, wrap = processUnderscoreApplication p args in
36713673
let exp =
36723674
let uncurried =
36733675
p.uncurried_config |> Res_uncurried.fromDotted ~dotted

0 commit comments

Comments
 (0)