Skip to content

Commit b09e088

Browse files
SamChou19815facebook-github-bot
authored andcommitted
[flow][refactor] Introduce use_unsound_fallback flag to Reason.mk_obj_lit_reason
Summary: Will be used later to implement a partial fix for unsound object literals. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D76283490 fbshipit-source-id: e67790e089c0736660df2b77eeda7fe66339dd07
1 parent 64c620c commit b09e088

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

src/common/reason.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,16 @@ let def_loc_of_reason r =
494494

495495
let annot_loc_of_reason r = r.annot_loc_opt
496496

497-
let mk_obj_lit_reason ~as_const ~frozen loc =
497+
let mk_obj_lit_reason ~as_const ~frozen ~use_unsound_fallback loc =
498498
let desc =
499499
if frozen then
500500
RFrozen RObjectLit
501501
else if as_const then
502502
RConstObjectLit
503-
else
503+
else if Lazy.force use_unsound_fallback then
504504
RObjectLit_UNSOUND
505+
else
506+
RObjectLit
505507
in
506508
mk_reason desc loc
507509

src/common/reason.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ val opt_annot_reason : ?annot_loc:'loc -> 'loc virtual_reason -> 'loc virtual_re
342342
(* create a new reason with annot_loc = loc: same as mk_reason followed by annot_reason *)
343343
val mk_annot_reason : 'loc virtual_reason_desc -> 'loc -> 'loc virtual_reason
344344

345-
val mk_obj_lit_reason : as_const:bool -> frozen:bool -> 'loc -> 'loc virtual_reason
345+
val mk_obj_lit_reason :
346+
as_const:bool -> frozen:bool -> use_unsound_fallback:bool Lazy.t -> 'loc -> 'loc virtual_reason
346347

347348
module ReasonMap : WrappedMap.S with type key = reason
348349

src/typing/statement.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,7 @@ module Make
24882488
and object_ cx ~frozen ~as_const ~has_hint loc props =
24892489
let open Ast.Expression.Object in
24902490
error_on_this_uses_in_object_methods cx props;
2491-
let reason = Reason.mk_obj_lit_reason ~as_const ~frozen loc in
2491+
let reason = Reason.mk_obj_lit_reason ~as_const ~frozen ~use_unsound_fallback:(lazy true) loc in
24922492
(* Use the same reason for proto and the ObjT so we can walk the proto chain
24932493
and use the root proto reason to build an error. *)
24942494
let obj_proto = ObjProtoT reason in

src/typing/type_sig_merge.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ and merge_declare_module_implicitly_exported_object env file (loc, module_name,
12031203
Obj_type.mk_with_proto file.cx reason proto ~obj_kind:Type.Exact ~props
12041204

12051205
and merge_object_lit ~for_export ~as_const env file (loc, frozen, proto, props) =
1206-
let reason = Reason.mk_obj_lit_reason ~as_const ~frozen loc in
1206+
let reason = Reason.mk_obj_lit_reason ~as_const ~frozen ~use_unsound_fallback:(lazy true) loc in
12071207
let proto =
12081208
match proto with
12091209
| None -> Type.ObjProtoT reason
@@ -1219,7 +1219,7 @@ and merge_object_lit ~for_export ~as_const env file (loc, frozen, proto, props)
12191219
Obj_type.mk_with_proto file.cx reason proto ~obj_kind:Type.Exact ~props
12201220

12211221
and merge_obj_spread_lit ~for_export ~as_const env file (loc, frozen, proto, elems_rev) =
1222-
let reason = Reason.mk_obj_lit_reason ~as_const ~frozen loc in
1222+
let reason = Reason.mk_obj_lit_reason ~as_const ~frozen ~use_unsound_fallback:(lazy true) loc in
12231223
(* TODO: fix spread to use provided __proto__ prop *)
12241224
ignore proto;
12251225
let merge_slice props =

0 commit comments

Comments
 (0)