Skip to content

Commit f9a66e8

Browse files
committed
Make suntyping 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 f9a66e8

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

jscomp/ml/ctype.ml

+3-3
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

+5
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

+7-4
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)