Skip to content

Commit 68a3f5c

Browse files
committed
Audit type invariant check for nested promises.
Fixes #5567
1 parent d1d8668 commit 68a3f5c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
- Add support for for `async`/`await` https://github.com/rescript-lang/rescript-compiler/pull/5537
2222

23+
- Make `promise` a built-in type https://github.com/rescript-lang/rescript-compiler/pull/5650
24+
2325
- Initial support for JSX V4 including genType, still work in progress.
2426

2527
- :boom: when V4 is activated, at most one component is allowed for each module.

jscomp/ml/typecore.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1869,16 +1869,20 @@ and type_expect ?in_function ?recarg env sexp ty_expected =
18691869
(Cmt_format.Partial_expression exp :: previous_saved_types);
18701870
exp
18711871

1872-
and checkTypeInvariant exp =
1872+
(* NOTE: the type invariant check should have no side effects and be efficient *)
1873+
and checkTypeInvariant exp : unit =
18731874
let rec extractPromise t =
18741875
match t.desc with
18751876
| Tconstr
18761877
(Pdot (Pdot (Pident { name = "Js" }, "Promise", _), "t", _), [ t1 ], _)
18771878
| Tconstr (Pident { name = "promise" }, [ t1 ], _) ->
1879+
(* Improvement: check for type aliases, if it can be done efficiently *)
18781880
Some t1
18791881
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> extractPromise t1
18801882
| _ -> None
18811883
in
1884+
(* Only traverse arguments of a type constructors and function types.
1885+
This should guarantee that the traversal finished quickly. *)
18821886
let rec findNestedPromise t =
18831887
match t.desc with
18841888
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> findNestedPromise t1

0 commit comments

Comments
 (0)