Skip to content

Commit 4d4b58b

Browse files
committed
Fix issue with partial application and user defined types.
Fixes #7544 Fix an issue in type checking partial application in the presence of user-defined function types. The type checking code, when extracting the arity of the type annotation given to a function being applied, was expecting a concrete function type instead of looking up a possible type definition.
1 parent 05be83f commit 4d4b58b

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- Fix `index out of bounds` exception thrown in rare cases by `rescript-editor-analysis.exe codeAction` command. https://github.com/rescript-lang/rescript/pull/7523
3737
- Don't produce duplicate type definitions for recursive types on hover. https://github.com/rescript-lang/rescript/pull/7524
3838
- Prop punning when types don't match results in I/O error: _none_: No such file or directory. https://github.com/rescript-lang/rescript/pull/7533
39+
- Fix partial application with user-defined function types. https://github.com/rescript-lang/rescript/pull/7548
3940

4041
#### :nail_care: Polish
4142

compiler/ml/typecore.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,10 +3481,9 @@ and type_application ~context total_app env funct (sargs : sargs) :
34813481
| _ -> false
34823482
in
34833483
let has_arity funct =
3484-
let t = funct.exp_type in
34853484
if force_tvar then Some (List.length sargs)
34863485
else
3487-
match (Ctype.repr t).desc with
3486+
match (expand_head env funct.exp_type).desc with
34883487
| Tarrow (_, _, _, _, Some arity) -> Some arity
34893488
| _ -> None
34903489
in
@@ -3538,7 +3537,7 @@ and type_application ~context total_app env funct (sargs : sargs) :
35383537
| _ -> new_t
35393538
in
35403539
(fully_applied, new_t)
3541-
| _ -> (false, new_t)
3540+
| None -> (false, new_t)
35423541
in
35433542
let rec type_unknown_args max_arity ~(args : lazy_args) ~top_arity omitted
35443543
ty_fun (syntax_args : sargs) : targs * _ =

tests/tests/src/PartialApplicationNoRuntimeCurry.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@ function f(u) {
1010
return extra => f$1(1, extra);
1111
}
1212

13+
function add$1(a, b) {
14+
return a + b | 0;
15+
}
16+
17+
function add5(extra) {
18+
return 5 + extra | 0;
19+
}
20+
1321
export {
14-
add,
1522
f,
23+
add$1 as add,
24+
add5,
1625
}
1726
/* No side effect */
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
@@uncurried
2-
31
let add = x => (y, z) => x + y + z
42

53
let f = u => {
64
let f = add(u)
75
f(1, ...)
86
}
7+
8+
// Test partial application with user-defined function type
9+
type fn2 = (int, int) => int
10+
let add: fn2 = (a, b) => a + b
11+
let add5: int => int = add(5, ...)

0 commit comments

Comments
 (0)