From f07f943f77da018dfd46aa3379be1944a1df47e7 Mon Sep 17 00:00:00 2001 From: Vassil Mladenov Date: Tue, 19 Dec 2017 15:55:10 -0800 Subject: [PATCH] Fixed list difference algorithm Summary: Changed $$\exists$$ to $$\forall$$ in filter. Reviewed By: jamesjwu Differential Revision: D6604685 fbshipit-source-id: 0e4483d806b81190f2a88ba4ff58f4cc42ceff82 --- hphp/hack/src/typing/typing_taccess.ml | 4 +++- .../generic_self_type_access_failure.php | 22 ++++++++++++++++++++++ .../generic_self_type_access_failure.php.exp | 22 ++++++++++++++++++++++ .../generic_self_type_access_failure.php.no_format | 0 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 hphp/hack/test/typecheck/constraints/generic_self_type_access_failure.php create mode 100644 hphp/hack/test/typecheck/constraints/generic_self_type_access_failure.php.exp create mode 100644 hphp/hack/test/typecheck/constraints/generic_self_type_access_failure.php.no_format diff --git a/hphp/hack/src/typing/typing_taccess.ml b/hphp/hack/src/typing/typing_taccess.ml index 6f69470b369..5025abf3c44 100644 --- a/hphp/hack/src/typing/typing_taccess.ml +++ b/hphp/hack/src/typing/typing_taccess.ml @@ -99,9 +99,11 @@ and expand_ env (root_reason, root_ty as root) = let upper_bounds = Env.get_upper_bounds env.tenv s in (* Ignore upper bounds that are equal to ones we've seen, to avoid an infinite loop + + let upper_bounds = upper_bounds - env.gen_seen *) let upper_bounds = List.filter ~f:(fun ty -> - List.exists env.gen_seen + List.for_all env.gen_seen ~f:(fun ty2 -> not (ty_equal ty ty2))) upper_bounds in let env, tyl = List.map_env env upper_bounds begin fun prev_env ty -> let env, ty = expand_ env ty in diff --git a/hphp/hack/test/typecheck/constraints/generic_self_type_access_failure.php b/hphp/hack/test/typecheck/constraints/generic_self_type_access_failure.php new file mode 100644 index 00000000000..f8e6c553944 --- /dev/null +++ b/hphp/hack/test/typecheck/constraints/generic_self_type_access_failure.php @@ -0,0 +1,22 @@ + { + abstract public function f(T $t): void + where TX::T = T; +} + +class Consumer { + // incorrectly constrains AbstractGeneric class + public function crash(AbstractGeneric $arg, T $t): void + where TX::T = T { + $arg->f($t); + } +} diff --git a/hphp/hack/test/typecheck/constraints/generic_self_type_access_failure.php.exp b/hphp/hack/test/typecheck/constraints/generic_self_type_access_failure.php.exp new file mode 100644 index 00000000000..faddbda0288 --- /dev/null +++ b/hphp/hack/test/typecheck/constraints/generic_self_type_access_failure.php.exp @@ -0,0 +1,22 @@ +File "generic_self_type_access_failure.php", line 18, characters 36-50: +Some type constraint(s) here are violated (Typing[4110]) + File "generic_self_type_access_failure.php", line 11, characters 32-33: + 'TX' is a constrained type parameter + File "generic_self_type_access_failure.php", line 18, characters 52-52: + 'T' is a constrained type parameter + File "generic_self_type_access_failure.php", line 11, characters 38-40: + This is an object of type Box + File "generic_self_type_access_failure.php", line 18, characters 30-33: + It is incompatible with an object of type Intf +File "generic_self_type_access_failure.php", line 13, characters 13-13: +Could not find type constant T in type Intf (Typing[4090]) + File "generic_self_type_access_failure.php", line 5, characters 11-14: + Declaration of Intf is here +File "generic_self_type_access_failure.php", line 20, characters 11-11: +A 'where' type constraint is violated here (Typing[4090]) + File "generic_self_type_access_failure.php", line 12, characters 28-28: + This method's where constraints contain a generic type access + File "generic_self_type_access_failure.php", line 13, characters 13-13: + Could not find type constant T in type Intf + File "generic_self_type_access_failure.php", line 5, characters 11-14: + Declaration of Intf is here diff --git a/hphp/hack/test/typecheck/constraints/generic_self_type_access_failure.php.no_format b/hphp/hack/test/typecheck/constraints/generic_self_type_access_failure.php.no_format new file mode 100644 index 00000000000..e69de29bb2d -- 2.11.4.GIT