Skip to content

Commit 055c70b

Browse files
Nikhil Thomasfacebook-github-bot
authored andcommitted
remove inside_constructor flag on Typing_env.env
Summary: # What We currently hold two flags on the typing environment 1) `env.inside_constructor` - set when we typecheck a constructor, then we call `method_def` in `typing_class.ml` 2) `env.genv.fun_is_ctor` - set when we call `method_def` in `typing_class.ml` by inspecting the name of the method and doing some string comparison. Given that these two fields do the same thing, I'm removing the one from `env`. # Why For const props, I'd like to enforce checking writes to a const prop during function calls, but not when typechecking method defs. I may need to carry another flag on the typing environment `inside_method_def` or something similar. Before adding a field, I figured I'd clean up here and pay off my cost. Reviewed By: mheiber Differential Revision: D83250939 fbshipit-source-id: 72a825dd8da6484909ff707c361d1d2d3de46bce
1 parent 8dd3143 commit 055c70b

5 files changed

Lines changed: 7 additions & 7 deletions

File tree

hphp/hack/src/typing/tast_env.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,13 @@ let get_underlying_function_type env ty =
118118
opt_ft
119119

120120
let set_inside_constructor env =
121-
{ env with Typing_env_types.inside_constructor = true }
121+
{
122+
env with
123+
Typing_env_types.genv =
124+
{ env.Typing_env_types.genv with fun_is_ctor = true };
125+
}
122126

123-
let get_inside_constructor env = env.Typing_env_types.inside_constructor
127+
let get_inside_constructor env = env.Typing_env_types.genv.fun_is_ctor
124128

125129
let fully_expand = Typing_expand.fully_expand
126130

hphp/hack/src/typing/typing_class.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,6 @@ let class_const_def ~in_enum_class c cls env cc =
12711271
ty ) )
12721272

12731273
let class_constr_def ~is_disposable env cls constructor =
1274-
let env = { env with inside_constructor = true } in
12751274
Option.bind constructor ~f:(method_def ~is_disposable env cls)
12761275

12771276
(** Type-check a property declaration, with optional initializer *)

hphp/hack/src/typing/typing_env_types.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type env = {
3838
in_lambda: bool;
3939
in_expr_tree: expr_tree_env option;
4040
in_macro_splice: Typing_local_types.t option;
41-
inside_constructor: bool;
4241
checked: Tast.check_status;
4342
tracing_info: Decl_counters.tracing_info option;
4443
tpenv: Type_parameter_env.t;
@@ -93,7 +92,6 @@ let empty ?origin ?(mode = FileInfo.Mstrict) ctx file ~droot =
9392
in_lambda = false;
9493
in_expr_tree = None;
9594
in_macro_splice = None;
96-
inside_constructor = false;
9795
checked = Tast.COnce;
9896
decl_env = { Decl_env.mode; droot; droot_member = None; ctx };
9997
tracing_info =

hphp/hack/src/typing/typing_env_types.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ type env = {
5151
contains nested expression trees with free variables. local_env contains
5252
the bindings for those free variables
5353
*)
54-
inside_constructor: bool;
5554
checked: Tast.check_status;
5655
(** Set to true when checking if a <<__SoundDynamicallyCallable>> method body
5756
is well-typed under dyn..dyn->dyn assumptions, that is if it can be safely called

hphp/hack/src/typing/typing_log.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,6 @@ let env_as_value env =
611611
in_lambda;
612612
in_expr_tree;
613613
in_macro_splice;
614-
inside_constructor;
615614
checked;
616615
tpenv;
617616
log_levels = _;
@@ -625,6 +624,7 @@ let env_as_value env =
625624
} =
626625
env
627626
in
627+
let inside_constructor = env.genv.fun_is_ctor in
628628
make_map
629629
[
630630
("fresh_typarams", Set fresh_typarams);

0 commit comments

Comments
 (0)