Skip to content

Commit 06fd254

Browse files
viratyosinmeta-codesync[bot]
authored andcommitted
tuple of class
Summary: Without this change, we don't match the old-refinement behavior w.r.t. supportdyn (https://fburl.com/code/dcmt01jv) (The ~is_class flag determines whether or not we wrap the type in supportdyn) I noticed this when updating the `as` keyword to behave using the new refinement logic Differential Revision: D89591115 fbshipit-source-id: 1116fc8d23a6fbf9075229c598c2637ab632ed30
1 parent 73272c8 commit 06fd254

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

hphp/hack/src/typing/typing.ml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7993,6 +7993,13 @@ end = struct
79937993
in
79947994
refine_local ty env
79957995
in
7996+
let rec is_class_or_tuple_of_class predicate =
7997+
match snd predicate with
7998+
| IsTag (ClassTag _) -> true
7999+
| IsTupleOf { tp_required } ->
8000+
List.exists ~f:is_class_or_tuple_of_class tp_required
8001+
| _ -> false
8002+
in
79968003
( env,
79978004
refine_local
79988005
ty_true
@@ -8002,10 +8009,7 @@ end = struct
80028009
Typing_logic.valid)
80038010
in
80048011
(env, predicate_ty))
8005-
~ty_refine_is_class:
8006-
(match predicate with
8007-
| (_, IsTag (ClassTag _)) -> true
8008-
| _ -> false),
8012+
~ty_refine_is_class:(is_class_or_tuple_of_class predicate),
80098013
refine_local
80108014
ty_false
80118015
(fun env -> (env, MakeType.neg reason predicate))
@@ -8059,10 +8063,16 @@ end = struct
80598063
(T223013561)
80608064
*)
80618065
let (env, inter) = Inter.intersect_list env reason tyl in
8066+
let rec is_class_or_tuple_of_class ty =
8067+
match get_node ty with
8068+
| Ttuple { t_required; _ } ->
8069+
List.exists t_required ~f:is_class_or_tuple_of_class
8070+
| _ -> Typing_utils.is_class ty
8071+
in
80628072
Typing_helpers.refine_and_simplify_intersection
80638073
~hint_first:false
80648074
env
8065-
~is_class:(Typing_utils.is_class refine)
8075+
~is_class:(is_class_or_tuple_of_class refine)
80668076
reason
80678077
inter
80688078
refine)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?hh
2+
3+
abstract class MyAbstract {
4+
abstract const type TOutput;
5+
6+
abstract public function getOutput(): this::TOutput;
7+
}
8+
9+
function my_fun2(MyAbstract $x): (int, dict<arraykey, mixed>) {
10+
$output = tuple(0, $x->getOutput());
11+
if ($output is (int, dict<_, _>)) {
12+
return $output;
13+
}
14+
throw new Exception();
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No errors

0 commit comments

Comments
 (0)