Check for void/noreturn in conditionals
[hiphop-php.git] / hphp / hack / test / typecheck / container_unbind.php
blob874d3feb19834d5337631a10a3bf298e23b022aa
1 <?hh //strict
3 class MyContainer<Tv> {
4 public function setPair(Pair<string, Tv> $_): void {}
5 public function setTuple((string, Tv) $_): void {}
6 public function setVector(Vector<Tv> $_): void {}
7 public function setMap(Map<string, Tv> $_): void {}
8 public function setMapArray(array<string, Tv> $_): void {}
9 public function setVectorArray(array<Tv> $_): void {}
10 public function setShape(shape('x' => Tv) $_): void {}
13 function take_int(int $_): void {}
15 function testPair(): void {
16 $x = Vector {4};
17 $y = Vector {'zzz'};
19 $m = new MyContainer();
21 // $x[0] and $y[0] are type variables that contain inferred types of elements
22 // in $x and $y - Pair constructor must remove (unbind) them, because in next
23 // two lines they would be unified with Tv type variable of $m, and
24 // transitively with each other. Putting element inside a container should
25 // not affect it's type.
26 $m->setPair(Pair {'x', $x[0]});
27 $m->setPair(Pair {'x', $y[0]});
29 take_int($x[0]);
32 function testTuple(): void {
33 $x = Vector {4};
34 $y = Vector {'zzz'};
36 $m = new MyContainer();
38 $m->setTuple(tuple('x', $x[0]));
39 $m->setTuple(tuple('x', $y[0]));
41 take_int($x[0]);
44 function testVector(): void {
45 $x = Vector {4};
46 $y = Vector {'zzz'};
48 $m = new MyContainer();
50 $m->setVector(Vector {$x[0]});
51 $m->setVector(Vector {$y[0]});
53 take_int($x[0]);
56 function testMap(): void {
57 $x = Vector {4};
58 $y = Vector {'zzz'};
60 $m = new MyContainer();
62 $m->setMap(Map {'x' => $x[0]});
63 $m->setMap(Map {'x' => $y[0]});
65 take_int($x[0]);
68 function testMapArray(string $key): void {
69 $x = Vector {4};
70 $y = Vector {'zzz'};
72 $m = new MyContainer();
74 $m->setMapArray(array($key => $x[0]));
75 $m->setMapArray(array($key => $y[0]));
77 take_int($x[0]);
80 function testVectorArray(): void {
81 $x = Vector {4};
82 $y = Vector {'zzz'};
84 $m = new MyContainer();
86 $m->setVectorArray(array($x[0]));
87 $m->setVectorArray(array($y[0]));
89 take_int($x[0]);
92 function testShape(): void {
93 $x = Vector {4};
94 $y = Vector {'zzz'};
96 $m = new MyContainer();
98 $m->setShape(shape('x' => $x[0]));
99 $m->setShape(shape('x' => $y[0]));
101 take_int($x[0]);
104 function testShapeLikeArray(): void {
105 $x = Vector {4};
106 $y = Vector {'zzz'};
108 $m = new MyContainer();
110 $m->setMapArray(array('x' => $x[0]));
111 $m->setMapArray(array('x' => $y[0]));
113 take_int($x[0]);