No error on use of `unsafe_cast`
[hiphop-php.git] / hphp / hack / test / typecheck / contravariance_unresolved_bad_2.php
blobaa52efebad25928215939322a876c49fa7614ae5
1 <?hh // strict
2 // Copyright 2004-present Facebook. All Rights Reserved.
4 interface I1<-T> {
5 public function f(T $t): int;
8 final class C1 implements I1<string> {
9 public function f(string $t): int {
10 return 42;
14 final class C2<T> {
15 public function __construct(private I1<T> $impl) {}
16 public function f(T $t): int {
17 return $this->impl->f($t);
21 class Foo {
22 public function BreakIt(): void {
23 $c1 = new C1();
25 // the following line is caught by type checker
26 // $c1->f(42);
28 $c2 = new C2($c1);
29 // What type do we expect for $c2?
30 // Perhaps C2<string>?
31 // What actually happens is
32 // $c2 : C2<v:=unresolved{}>
33 // and then check C1 <: I1<v:=unresolved{}>
34 // and so I1<string> <: I1<v:=unresolved{}>
35 // and so v:=unresolved{} <: string
37 // the following line fails in runtime
38 $c2->f(42);
42 function main(): void {
43 (new Foo())->BreakIt();