Skip to content

Commit f07cf05

Browse files
SamChou19815meta-codesync[bot]
authored andcommitted
[flow] Detect and ban cylic object type through prototype
Summary: Changelog: [errors] Bad cyclic object types are now banned. e.g. `type O_loop = { p: 0, __proto__: O_loop }` will cause an error. Reviewed By: panagosg7 Differential Revision: D85918437 fbshipit-source-id: eef2ff4c8518d734d75ac437447d727b5d641d85
1 parent 09eeded commit f07cf05

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/typing/flow_js_utils.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ end = struct
9797
match t with
9898
(* composite types that allow self or cyclic reference *)
9999
| DefT (_, FunT _)
100-
| DefT (_, ObjT _)
101100
| DefT (_, ArrT _)
102101
| DefT (_, InstanceT _)
103102
| DefT (_, ReactAbstractComponentT _)
@@ -108,6 +107,7 @@ end = struct
108107
| TypeAppT _
109108
| ThisTypeAppT _ ->
110109
acc
110+
| DefT (_, ObjT { proto_t; _ }) -> super#type_ cx pole acc proto_t
111111
(* EvalT(t, d, _) behaves like TypeAppT, not everything there will be unconditionally
112112
* evaluated, but if we do have the eval result, we should visit it, since at that point,
113113
* the EvalT behaves like an OpenT. *)

tests/proto/proto.exp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ References:
210210
^^^^^ [2]
211211

212212

213+
Error --------------------------------------------------------------------------------------------------- annot.js:35:34
214+
215+
Invalid trivially recursive definition of prototype. [recursive-definition]
216+
217+
35| type O_loop = { p: 0, __proto__: O_loop };
218+
^^^^^^
219+
220+
213221
Error ---------------------------------------------------------------------------------------------------- annot.js:37:2
214222

215223
Cannot cast `o_loop.p` to empty because number literal `0` [1] is incompatible with empty [2]. [incompatible-type]
@@ -492,4 +500,4 @@ References:
492500

493501

494502

495-
Found 34 errors
503+
Found 35 errors

0 commit comments

Comments
 (0)