No error on use of `unsafe_cast`
[hiphop-php.git] / hphp / hack / test / typecheck / constraint_generic.php
bloba86d24b1252b9dfb2b054c88b81c326370a0446a
1 <?hh // strict
2 /**
3 * Copyright (c) 2014, Facebook, Inc.
4 * All rights reserved.
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the "hack" directory of this source tree.
12 interface A {
13 public function render(): string;
16 class B implements A {
17 public function render(): string { return 'foo'; }
20 function toto(A $x): void {
24 function foo<T as A>(Vector<T> $x): Vector<T> {
25 $x[0]->render();
26 toto($x[0]);
27 return $x;
30 function test_vector(): void {
31 $x = foo(Vector {new B()});
34 function foo2<T as A>(T $x): T {
35 $x->render();
36 return $x;
40 class X {
42 public function foo<T as A>(T $x): T {
43 $x->render();
44 return $x;
49 class Y extends X implements A {
51 public function test(): Y {
52 return $this->foo($this);
55 public function render(): string {
56 return '0';
60 function test(): Vector<B> {
61 $x = new B();
62 return foo(Vector {});
66 class L<T as A> {
67 private ?T $data = null;
69 public function set(T $x): void { $this->data = $x; }
70 public function get(): ?T { return $this->data; }
73 function test2(): void {
74 $x = new L();
75 $x->set(new B());
78 class U<T as A> extends L<T> {
79 public function get(): ?T { return parent::get(); }
82 function test3(): void {
83 $x = new U();
86 function test4<T1, T2, T3 as KeyedIterable<T1, T2>>(T3 $x): void {
87 foreach($x as $k => $v) {
88 $k; $v;
92 function test5<T as ?int>(T $x): T {
93 return $x;