Skip to content

Commit 8d07220

Browse files
committed
Make subtyping in uncurried mode work past type definitions.
Subtyping from uncurried to curried functions was not working when the expected curried function was under a type definition. This would give type errors on components that take a component type as prop.
1 parent a5c7568 commit 8d07220

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ subset of the arguments, and return a curried type with the remaining ones https
2626
- Support optional named arguments without a final unit in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5907
2727
- Add support for uncurried mode: a mode where everything is considered uncurried, whether with or without the `.`. This can be turned on with `@@uncurried` locally in a file. For project-level configuration in `bsconfig.json`, there's a boolean config `"uncurried"`, which propagates to dependencies, to turn on uncurried mode.
2828
Since there's no syntax for partial application in this new mode, introduce `@res.partial foo(x)` to express partial application. This is temporary and will later have some surface syntax.
29+
Make uncurried functions a subtype of curried functions, and allow application for uncurried functions.
2930
Use best effort to determine the config when formatting a file.
30-
https://github.com/rescript-lang/rescript-compiler/pull/5968 https://github.com/rescript-lang/rescript-compiler/pull/6080
31+
https://github.com/rescript-lang/rescript-compiler/pull/5968 https://github.com/rescript-lang/rescript-compiler/pull/6080 https://github.com/rescript-lang/rescript-compiler/pull/6086
3132

3233
#### :boom: Breaking Change
3334

jscomp/ml/ctype.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,9 +2341,6 @@ let rec unify (env:Env.t ref) t1 t2 =
23412341
with Cannot_expand ->
23422342
unify2 env t1 t2
23432343
end
2344-
| (Tconstr (Pident {name="function$"}, [tFun; _], _), Tarrow _) when !Config.uncurried = Uncurried ->
2345-
(* subtype: an uncurried function is cast to a curried one *)
2346-
unify2 env tFun t2
23472344
| _ ->
23482345
unify2 env t1 t2
23492346
end;
@@ -2399,6 +2396,9 @@ and unify3 env t1 t1' t2 t2' =
23992396
link_type t2' t1;
24002397
| (Tfield _, Tfield _) -> (* special case for GADTs *)
24012398
unify_fields env t1' t2'
2399+
| (Tconstr (Pident {name="function$"}, [tFun; _], _), Tarrow _) when !Config.uncurried = Uncurried ->
2400+
(* subtype: an uncurried function is cast to a curried one *)
2401+
unify2 env tFun t2
24022402
| _ ->
24032403
begin match !umode with
24042404
| Expression ->

jscomp/test/UncurriedAlways.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ function bar3(__x) {
4343
return foo3(__x, 3, 4);
4444
}
4545

46+
function q(param) {
47+
return null;
48+
}
49+
4650
exports.foo = foo;
4751
exports.z = z;
4852
exports.bar = bar;
@@ -54,4 +58,5 @@ exports.foo2 = foo2;
5458
exports.bar2 = bar2;
5559
exports.foo3 = foo3;
5660
exports.bar3 = bar3;
61+
exports.q = q;
5762
/* Not a pure module */

jscomp/test/UncurriedAlways.res

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ let a = 3->foo(. 4)
1414

1515
Js.log(a) // Test automatic uncurried application
1616

17-
let _ = Js.Array2.map([1], (. x) => x+1)
17+
let _ = Js.Array2.map([1], (. x) => x + 1)
1818

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

21-
let foo2 = (x,y) => x+y
21+
let foo2 = (x, y) => x + y
2222
let bar2: _ => _ = foo2(_, 3)
2323

24-
let foo3 = (x,y,z) => x+y+z
25-
let bar3 : _ => _ = foo3(_, 3, 4)
24+
let foo3 = (x, y, z) => x + y + z
25+
let bar3: _ => _ = foo3(_, 3, 4)
26+
27+
type cmp = Jsx.component<int>
28+
let q: cmp = _ => Jsx.null // Check that subtyping works past type definitions

0 commit comments

Comments
 (0)