Skip to content

Commit 01223ea

Browse files
Michael Thomasfacebook-github-bot
authored andcommitted
Modify reasons when simplifying tyvars in bounds
Summary: Applies the same logic used in type expansion to the simplification of tyvars occurring in the bounds of other tyvars Reviewed By: vassilmladenov Differential Revision: D63749805 fbshipit-source-id: d28f3d80e906f698fd5793a39dac62ece695e167
1 parent a4ee5ed commit 01223ea

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

hphp/hack/src/typing/env/typing_env.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ let bind env v ty = { env with inference_env = Inf.bind env.inference_env v ty }
189189
190190
The simplification is recursive: simplifying a type variable will
191191
trigger simplification of its own occurrences. *)
192-
let simplify_occurrences env v =
192+
let simplify_occurrences env v r =
193193
let rec simplify_occurrences env v ~seen_tyvars =
194194
let vars = Inf.get_tyvar_occurrences env.inference_env v in
195195
let (env, seen_tyvars) =
@@ -227,6 +227,10 @@ let simplify_occurrences env v =
227227
(* we only call this function when v does not recursively contain unsolved
228228
type variables, so ty here should not contain unsolved type variables and
229229
it is safe to simply bind it without reupdating the type var occurrences. *)
230+
let ty =
231+
map_reason ty ~f:(fun solution ->
232+
Typing_reason.(solved v ~solution ~in_:r))
233+
in
230234
let env = bind env v ty in
231235
env
232236
in
@@ -241,7 +245,8 @@ let add env ?(tyvar_pos = Pos.none) v ty =
241245
let env =
242246
{ env with inference_env = Inf.add env.inference_env ~tyvar_pos v ty }
243247
in
244-
let env = simplify_occurrences env v in
248+
let r = get_reason ty in
249+
let env = simplify_occurrences env v r in
245250
env
246251

247252
let get_type env r var =

0 commit comments

Comments
 (0)