Skip to content

Commit 7588666

Browse files
committed
Fix type inference issue with uncurried functions applied to a single unit argument.
In the example the inferred for `func()` was the return type `int` instead of the type `unit => int` because the application `()` was omitted, as the heuristic for application of a function with only optional args would mistakenly fire.
1 parent abb5822 commit 7588666

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ These are only breaking changes for unformatted code.
5252
- Fix some comments disappearing in array access expressions https://github.com/rescript-lang/rescript-compiler/pull/5947
5353
- Parser: fix location of variable when function definition `{v => ...}` is enclosed in braces https://github.com/rescript-lang/rescript-compiler/pull/5949
5454
- Fix issue where error messages related to non-existent props were displayed without location information https://github.com/rescript-lang/rescript-compiler/pull/5960
55+
- Fix type inference issue with uncurried functions applied to a single unit argument. The issue was introduced in https://github.com/rescript-lang/rescript-compiler/pull/5907 when adding support to `foo()` when `foo` has only optional arguments. https://github.com/rescript-lang/rescript-compiler/pull/5970
5556

5657
#### :nail_care: Polish
5758

jscomp/ml/typecore.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3047,7 +3047,7 @@ and type_application uncurried env funct (sargs : sargs) : targs * Types.type_ex
30473047
else
30483048
collect_args ()
30493049
| [(Nolabel, {pexp_desc = Pexp_construct ({txt = Lident "()"}, None)})]
3050-
when uncurried && omitted = [] && List.length args = List.length !ignored ->
3050+
when uncurried && omitted = [] && args <> [] && List.length args = List.length !ignored ->
30513051
(* foo(. ) treated as empty application if all args are optional (hence ignored) *)
30523052
type_unknown_args max_arity args omitted ty_fun []
30533053
| (l1, sarg1) :: sargl ->

jscomp/test/uncurried_default.args.js

+9
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ function foo3$1(xOpt, yOpt) {
101101

102102
var r3$1 = foo3$1(undefined, undefined);
103103

104+
function foo(func) {
105+
return func(undefined) + 1 | 0;
106+
}
107+
108+
var M = {
109+
foo: foo
110+
};
111+
104112
exports.StandardNotation = StandardNotation;
105113
exports.withOpt = withOpt$1;
106114
exports.testWithOpt = testWithOpt$1;
@@ -112,4 +120,5 @@ exports.foo2 = foo2$1;
112120
exports.r2 = r2$1;
113121
exports.foo3 = foo3$1;
114122
exports.r3 = r3$1;
123+
exports.M = M;
115124
/* testWithOpt Not a pure module */

jscomp/test/uncurried_default.args.res

+6
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ let r2 = foo2(~y=11)
3131

3232
let foo3 = (~x=3, ~y=4) => x+y
3333
let r3 = foo3()
34+
35+
module M: {
36+
let foo: (unit => int) => int
37+
} = {
38+
let foo = func => func() + 1
39+
}

0 commit comments

Comments
 (0)