Fully expand type variables in Tgenerics
commit6bb640c02927d0c418d46f2318f4fe304fe0d5d3
authorDwayne Reeves <dreeves@fb.com>
Thu, 18 Jun 2015 15:15:23 +0000 (18 08:15 -0700)
committerhhvm-bot <hhvm-bot@fb.com>
Thu, 18 Jun 2015 15:32:45 +0000 (18 08:32 -0700)
tree443f08d2d795394d97f2d16557274eacf3f42bb2
parent8b579c69fcd8e51e68deb2557972e9d7bf6f1979
Fully expand type variables in Tgenerics

Summary: Typing_expand.fully_expand is used whenever we need to fully expand out any
type variables. One instance where this occurs is making sure we do not store
polymorphic value into a static scoped variable. The reason this is unsound is
demonstrated in the test case I added static_var_no_generic.php

Essientially due to the way static scoped variables, new static(), and
self::method() work, it is possible to trick the type checker that a type
parameter is bound to the improper type. In order to safely use the pattern
in static_var_no_generic.php a type constant should be used instead. Then if we
only know that a type is a ##Singleton## the get method will return an abstract
type.

The reason this is currently not an error is because the "this" type is
represented as a generic so we never expand the type variables that are
substituted for its type parameters. That combined with the fact in
don't detect this error case.

Reviewed By: @int3

Differential Revision: D2165262
hphp/hack/src/typing/typing_expand.ml
hphp/hack/src/typing/typing_generic.ml
hphp/hack/test/typecheck/static_var_no_generic.php [new file with mode: 0644]
hphp/hack/test/typecheck/static_var_no_generic.php.exp [new file with mode: 0644]