Do not ignore declared variance of generics with constraints
commit86334bdde5e4af4cd3addb242d52ea0fee9f5d62
authorDwayne Reeves <dreeves@fb.com>
Fri, 19 Feb 2016 22:45:21 +0000 (19 14:45 -0800)
committerhhvm-bot <hhvm-bot@fb.com>
Fri, 19 Feb 2016 23:00:50 +0000 (19 15:00 -0800)
tree4d59e9e2671ce09cd0bccb20b6f5e20e0b6f5b35
parent2b03a69f381580eba8e2b66360e129797ea178c2
Do not ignore declared variance of generics with constraints

Summary:Let's take a look at this simplified example

```
class Foo<+T as int> {
  public function bar(T): void {}
}
```

Previously we would allow this code to type check because we ignored the
variance specified on `T` since it has a constraint. Reading the comments the
reason was that the constraint does not have the same variance as the generic
itself, but is contravariant for `as` constraints, yet covariant for `super`.
While this is true we should not ignore the specified variance of the generic
like we currently are doing, instead we should include the variance of the
generic, but add additional variance constraints for the `as` or `super`
constraint.

Reviewed By: int3

Differential Revision: D2922621

fb-gh-sync-id: ad324b29cfc1259c7c7da1e3fb4d36d5775ffeec
shipit-source-id: ad324b29cfc1259c7c7da1e3fb4d36d5775ffeec
hphp/hack/src/typing/typing_variance.ml
hphp/hack/test/typecheck/covariance12.php [new file with mode: 0644]
hphp/hack/test/typecheck/covariance12.php.exp [new file with mode: 0644]