New inference: improved error message for unresolved type
[hiphop-php.git] / hphp / hack / test / typecheck / contravariance1.php
blob32da325b6a7d5d4c8ef242ff5e075910bae903b3
1 <?hh // partial
3 class Foo<-T> {
4 public function __construct(T $x) {}
7 class A {}
8 class B extends A {}
10 function fa(Foo<A> $x) {}
11 function fb(Foo<B> $y) {}
13 function g() {
14 // $x has type B and therefore also type A
15 $x = new B();
16 // $y can be assigned type Foo<A> because B <: A
17 $y = new Foo($x);
18 // So this is actually legal
19 fa($y);
20 // By contravariance we can also pass it to something expecting Foo<B>
21 fb($y);