From 535556ff2f93b757647eeca5e3348667223e62af Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Mar 2023 11:10:28 +0100 Subject: [PATCH] Fix underscore in uncurried mode. --- CHANGELOG.md | 1 + jscomp/test/UncurriedAlways.js | 20 ++++++++++++++++++++ jscomp/test/UncurriedAlways.res | 6 ++++++ res_syntax/src/res_core.ml | 8 +++++--- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cb4c24650..321b36a47b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jscomp/test/UncurriedAlways.js b/jscomp/test/UncurriedAlways.js index ba84db9d57..7cfcf4dff8 100644 --- a/jscomp/test/UncurriedAlways.js +++ b/jscomp/test/UncurriedAlways.js @@ -27,6 +27,22 @@ 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; @@ -34,4 +50,8 @@ 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 */ diff --git a/jscomp/test/UncurriedAlways.res b/jscomp/test/UncurriedAlways.res index 63d8e25899..5da60a0852 100644 --- a/jscomp/test/UncurriedAlways.res +++ b/jscomp/test/UncurriedAlways.res @@ -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) diff --git a/res_syntax/src/res_core.ml b/res_syntax/src/res_core.ml index ca3dc4275e..a08180a9e6 100644 --- a/res_syntax/src/res_core.ml +++ b/res_syntax/src/res_core.ml @@ -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) = @@ -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) @@ -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