Skip to content

Commit c9f8eeb

Browse files
madgenfacebook-github-bot
authored andcommitted
Fix convergence condition for loops
Summary: We were only looking for stability of the Next continuation to establish that the typing environment reached a fixpoint. This is unsound. This diff fixes it by looking for stability of all continuations. Reviewed By: andrewjkennedy Differential Revision: D36345984 fbshipit-source-id: ade3cdca30f0e28393d6b1e93c5b3a43e701aad9
1 parent 7becd74 commit c9f8eeb

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

hphp/hack/src/typing/typing.ml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,17 +2289,21 @@ and stmt_ env pos st =
22892289
let env = { env with in_loop = true } in
22902290
let rec loop env n =
22912291
(* Remember the old environment *)
2292-
let old_next_entry = Env.next_cont_opt env in
2292+
let old_conts = env.lenv.per_cont_env in
22932293
let (env, result) = f env in
2294-
let new_next_entry = Env.next_cont_opt env in
2294+
let new_conts = env.lenv.per_cont_env in
22952295
(* Finish if we reach the bound, or if the environments match *)
22962296
if
22972297
Int.equal n alias_depth
2298-
|| Typing_per_cont_ops.is_sub_opt_entry
2299-
Typing_subtype.is_sub_type
2300-
env
2301-
new_next_entry
2302-
old_next_entry
2298+
|| CMap.for_all2
2299+
~f:(fun _ old_cont_entry new_cont_entry ->
2300+
Typing_per_cont_ops.is_sub_opt_entry
2301+
Typing_subtype.is_sub_type
2302+
env
2303+
new_cont_entry
2304+
old_cont_entry)
2305+
old_conts
2306+
new_conts
23032307
then
23042308
let env = { env with in_loop = in_loop_outer } in
23052309
(env, result)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
File "T120247995.php", line 10, characters 13-16:
2+
You are trying to access the method `ohno` but this is an int (Typing[4062])
3+
File "interfaces.hhi", line 92, characters 46-47:
4+
Definition is here

hphp/hack/test/typecheck/control_flow/lambda.php.exp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ File "lambda.php", line 51, characters 11-21:[2]
1414
[unresolved]
1515
File "lambda.php", line 71, characters 9-19:[2]
1616
([unresolved] | exact D | exact G | exact J)
17+
File "lambda.php", line 23, characters 5-15:[3]
18+
(exact A | exact B | exact C)
19+
File "lambda.php", line 24, characters 5-15:[3]
20+
(exact A | exact B | exact C)
21+
File "lambda.php", line 51, characters 11-21:[3]
22+
[unresolved]
23+
File "lambda.php", line 71, characters 9-19:[3]
24+
([unresolved] | exact D | exact G | exact J)
1725
File "lambda.php", line 86, characters 3-13:
1826
(exact A | exact B | exact C | exact E)
1927
File "lambda.php", line 87, characters 3-13:

hphp/hack/test/typecheck/typehole/T120247995.php.exp

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)