From e9eebb939e3825e503903d9939c69d504f74ee91 Mon Sep 17 00:00:00 2001 From: Dwayne Reeves Date: Sat, 11 Jul 2015 12:02:13 -0700 Subject: [PATCH] Fix infinite recursion in Typing_utils.simplified_uerror Summary: Had a bug where we would continually try to simplify an unification error produced by an unconstraint expression dependent type. When checking if we should simplify I need to make sure its not only a expression dependent type but also wraps some base type. Reviewed By: @int3 Differential Revision: D2235706 --- hphp/hack/src/typing/typing_utils.ml | 4 ++-- hphp/hack/test/typecheck/tconst/simplify_error.php | 14 ++++++++++++++ hphp/hack/test/typecheck/tconst/simplify_error.php.exp | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 hphp/hack/test/typecheck/tconst/simplify_error.php create mode 100644 hphp/hack/test/typecheck/tconst/simplify_error.php.exp diff --git a/hphp/hack/src/typing/typing_utils.ml b/hphp/hack/src/typing/typing_utils.ml index 87ac4579361..57e463c209e 100644 --- a/hphp/hack/src/typing/typing_utils.ml +++ b/hphp/hack/src/typing/typing_utils.ml @@ -88,8 +88,8 @@ let simplified_uerror env ty1 ty2 = let simplify = match snd ty1, snd ty2 with | Tabstract (AKdependent (`static, []), _), Tclass _ | Tclass _, Tabstract (AKdependent (`static, []), _) -> false - | Tabstract (AKdependent _, _), _ - | _, Tabstract (AKdependent _, _) -> true + | Tabstract (AKdependent _, Some _), _ + | _, Tabstract (AKdependent _, Some _) -> true | _, _ -> false in (* We unify the base types to see if that produces an error, if not then * we use the standard unification error diff --git a/hphp/hack/test/typecheck/tconst/simplify_error.php b/hphp/hack/test/typecheck/tconst/simplify_error.php new file mode 100644 index 00000000000..0dc1ae5c57a --- /dev/null +++ b/hphp/hack/test/typecheck/tconst/simplify_error.php @@ -0,0 +1,14 @@ + { + abstract protected function foo(): T; +} + +abstract class C extends P { + abstract const type T; + // Silence the Naming phase errors so we see the + // unification error + /* HH_IGNORE_ERROR[2002] */ + /* HH_IGNORE_ERROR[2049] */ + abstract protected function foo(): T; +} diff --git a/hphp/hack/test/typecheck/tconst/simplify_error.php.exp b/hphp/hack/test/typecheck/tconst/simplify_error.php.exp new file mode 100644 index 00000000000..c403ffa30a7 --- /dev/null +++ b/hphp/hack/test/typecheck/tconst/simplify_error.php.exp @@ -0,0 +1,14 @@ +File "simplify_error.php", line 7, characters 16-16: +This object is of type C (Typing[4110]) +File "simplify_error.php", line 7, characters 26-26: +It is incompatible with this object of type P +because some declarations are incompatible. +Read the following to see why: +File "simplify_error.php", line 7, characters 28-34: +This is the abstract type constant C::T +File "simplify_error.php", line 4, characters 38-38: + via this generic T +File "simplify_error.php", line 8, characters 23-23: + resulting from expanding the type constant C::T +File "simplify_error.php", line 13, characters 38-38: +It is incompatible with an object of type T -- 2.11.4.GIT