Skip to content

Fix underscore in uncurried mode. #6082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ These are only breaking changes for unformatted code.
- Fix issue with error messages for uncurried functions where expected and given type were swapped https://github.com/rescript-lang/rescript-compiler/pull/5973
- Fix issue with integer overflow check https://github.com/rescript-lang/rescript-compiler/pull/6028
- Make internal encoding of locations aware of unicode https://github.com/rescript-lang/rescript-compiler/pull/6073
- Fix issue where `foo(x,_)` in uncurried mode would generate a curried function https://github.com/rescript-lang/rescript-compiler/pull/6082

#### :nail_care: Polish

Expand Down
20 changes: 20 additions & 0 deletions jscomp/test/UncurriedAlways.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,31 @@ function ptl(param) {
return foo(10, param);
}

function foo2(x, y) {
return x + y | 0;
}

function bar2(__x) {
return __x + 3 | 0;
}

function foo3(x, y, z) {
return (x + y | 0) + z | 0;
}

function bar3(__x) {
return foo3(__x, 3, 4);
}

exports.foo = foo;
exports.z = z;
exports.bar = bar;
exports.b = b;
exports.w = w;
exports.a = a;
exports.ptl = ptl;
exports.foo2 = foo2;
exports.bar2 = bar2;
exports.foo3 = foo3;
exports.bar3 = bar3;
/* Not a pure module */
6 changes: 6 additions & 0 deletions jscomp/test/UncurriedAlways.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ Js.log(a) // Test automatic uncurried application
let _ = Js.Array2.map([1], (. x) => x+1)

let ptl = @res.partial foo(10) // force partial application

let foo2 = (x,y) => x+y
let bar2: _ => _ = foo2(_, 3)

let foo3 = (x,y,z) => x+y+z
let bar3 : _ => _ = foo3(_, 3, 4)
8 changes: 5 additions & 3 deletions res_syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ let wrapTypeAnnotation ~loc newtypes core_type body =
* return a wrapping function that wraps ((__x) => ...) around an expression
* e.g. foo(_, 3) becomes (__x) => foo(__x, 3)
*)
let processUnderscoreApplication args =
let processUnderscoreApplication (p : Parser.t) args =
let exp_question = ref None in
let hidden_var = "__x" in
let check_arg ((lab, exp) as arg) =
Expand All @@ -537,7 +537,9 @@ let processUnderscoreApplication args =
(Ppat_var (Location.mkloc hidden_var loc))
~loc:Location.none
in
Ast_helper.Exp.mk (Pexp_fun (Nolabel, None, pattern, exp_apply)) ~loc
let funExpr = Ast_helper.Exp.fun_ ~loc Nolabel None pattern exp_apply in
if p.uncurried_config = Legacy then funExpr
else Ast_uncurried.uncurriedFun ~loc ~arity:1 funExpr
| None -> exp_apply
in
(args, wrap)
Expand Down Expand Up @@ -3667,7 +3669,7 @@ and parseCallExpr p funExpr =
List.fold_left
(fun callBody group ->
let dotted, args = group in
let args, wrap = processUnderscoreApplication args in
let args, wrap = processUnderscoreApplication p args in
let exp =
let uncurried =
p.uncurried_config |> Res_uncurried.fromDotted ~dotted
Expand Down