Check for void/noreturn in conditionals
[hiphop-php.git] / hphp / hack / test / typecheck / typing_fail_test.php
blob33d4ef799150f6a83ad094004598699aec3e27d8
1 <?hh
2 /**
3 * Copyright (c) 2014, Facebook, Inc.
4 * All rights reserved.
6 * This source code is licensed under the BSD-style license found in the
7 * LICENSE file in the "hack" directory of this source tree. An additional grant
8 * of patent rights can be found in the PATENTS file in the same directory.
13 int function toto2(hashtable(string, int) $h) {
14 $x = "";
15 $y = 0;
16 if($x == "xx") {
18 else {
19 $x = 9;
21 $h['foo'] = 0;
22 return 0;
26 Error argument already bound
27 num function my_plus(num $x, num $x) {
32 Error float and int
33 int function my_plus(num $x, num $y) {
34 return $x + $y + 1.0;
39 int function f(int $x) {
40 $y = null;
41 $x = $y;
46 int function f(option(int) $y) {
47 if($y) {
48 return $y+1;
49 } else {
55 int function f(option(int) $y) {
56 if($y) {
57 return $y+1;
58 } else {
60 return 0;
65 class X {
67 private $x;
69 function __construct() {
72 int function get() {
73 return $this->x;
80 int function f(int $n, int $y = 0) {
81 if($n == 0) {
82 return 1;
84 return f(0);
88 int function get(option(int) $x) {
89 if($x) {
90 return $x;
92 return 0;
96 T function id(T $x) {
97 return $x;
100 string function test() {
101 $x = id(0);
102 $y = id("dfa");
103 return $y;
109 class C<T> {
111 public T $x;
113 public function __construct(T $x) {
114 $this->x = $x;
117 public T function set_x(T $x) {
118 $this->x = $x;
119 return $x;
122 public T function get_x() {
123 return $this->x;
127 int function f() {
128 $x = new C();
129 $y = $x->set_x(22);
130 $c2 = new C();
131 $z = $c2->get_x();
132 return $z;
135 int function f2(option(int) $x) {
136 if($x) {
137 return $x;
139 else {
140 return 0;
144 T function show(T $x) { return $x; }
147 class A {
148 public option(int) $x;
150 public function __construct() {
151 $this->x = some(0);
154 public bool function get_x() {
155 $x = $this->x;
156 if ($x) {
158 $z = $x + 1;
159 return true;
166 //testing unify_fun_strict
167 class A {
168 public int function f(bool $x = true, bool $h = true) {
169 return 0;
173 class B {
174 public int function f(bool $x, bool $y = true) {
175 return 1;
179 int function x() {
180 $x = new A();
181 if(true) {
182 $x = new B();
184 return $x->f();
189 class A {
190 public bool function f(A $x) { return true; }
193 class B {
196 bool function test() {
197 $a = new A();
198 $b = new B();
199 $u = $a->f($b);
200 return false;
205 class A {
207 public A function f(A $x) {
208 if(true) {
209 return $x;
211 else {
212 return $x->f(new A());
220 class A {
221 public A function f(A $x) { return $x; }
224 class B {
225 public B function f(B $x) { return $x; }
226 public B function g(B $x) { return $x; }
229 bool function test() {
230 $a = new A();
231 if(true) {
232 $a = new B();
234 $z = $a->f($a);
235 $z = $z->g($z);
236 return false;
242 class A {
243 public A function f(A $x) {
244 $z = show($x);
245 return $x;
250 class B {
251 public B function f(B $x) { return $x; }
252 public B function g(B $x) { return $x; }
256 bool function test() {
257 $a = new A();
258 $x = $a->f($a);
259 $uu = show($x);
260 $uuu = $a->g($x);
261 return false;
266 class L<T> {
267 private T $v;
269 public function __construct(T $x) {
270 $this->v = $x;
273 public bool function append(T $x) {
274 $this->v = $x;
275 return true;
278 public T function get() {
279 return $this->v;
285 class A {
286 bool function f(bool $x) { return true; }
289 class B {
290 bool function f(bool $x) { return true; }
291 bool function g(bool $x) { return true; }
294 class C {
295 bool function f(bool $x) { return true; }
296 bool function h(bool $x) { return true; }
302 bool function justA(A $x) { return true;}
303 bool function justC(C $x) { return true;}
305 bool function tt() {
306 $y = Map {'f00' => new A()};
307 $t = tuple(1, new A());
308 $v = Vector{};
309 $v[0] = 0.0;
310 $x = $y['f00'];
311 if(true) {
312 $x = $t[1];
314 return true;
320 bool function test(L<A> $l) {
321 // $zz = $l->append(new C());
322 return true;
326 class XX {
328 B function test44(L<A> $l) {
330 $zz = justC(new A());
332 return new B();
338 bool function xx(A $x) {
339 return true;
342 bool function yy() {
343 $x = new B();
344 $zz = xx($x);
345 $zz = $x->g(true);
346 return true;
351 bool function test2() {
352 $x = test(new L());
353 return $x->get()->f(true);
358 class A<T> {
359 public A<T> function f(T $x) {
360 return $this->f(new A());
366 class A<T1, T2> {
367 public A<T2, T1> function f(A<T1, T2> $x) {
368 return $x;
374 class A<T1, T2> {
376 public T1 function f(T1 $x) {
377 return $x;
379 public T2 function g(T2 $x) {
380 return $x;
384 class B {
385 public float function f(int $x) {
386 return 5.1;
388 public bool function g(bool $x, int $y = 0) {
389 return $x;
393 class C<T1, T2> {
394 public T2 function f(T2 $x) {
395 return $x;
398 public T1 function g(T1 $x) {
399 return $x;
403 bool function test3() {
404 return (new C() == new A());
411 bool function test2() {
412 $b = new B();
413 $a = new A();
414 if(true) {
415 $b = $a;
417 $z = $b->g(true, 1);
418 return true;
423 option(T) function f(T $x) {
424 return f($x);
429 bool function f() {
430 $x = 1.0;
432 $z = 0;
434 $y = 0.0;
436 if (true) {
437 $y = $x;
438 } else {
439 $y = $z;
442 return $y;
447 class C1 {
450 class C2 {
451 public int function f() { return 0; }
454 class A {
455 option(C1) function f(bool $x) { return null; }
458 class B {
459 option(C2) function f(bool $x, bool $y = true) { return null; }
460 bool function g(bool $x) { return true; }
463 bool function test(A $x, int $y) {
464 return true;
467 bool function test2() {
468 $b = new B();
469 $z = test($b, 1);
470 $z = show($b);
471 return true;
478 class A {
479 bool function f(bool $x) { return true; }
482 class B {
483 bool function f(bool $x) { return true; }
484 bool function g(bool $x) { return true; }
488 class XX {
490 public B $x;
492 public function __construct(A $x) {
493 $this->x = $x;
498 bool function f(bool $x) {
499 $y = new A();
500 $y->f(true);
501 return true;
506 class A {
507 public A function f(A $x) { return new A(); }
510 class B {
511 public A function f(A $x) { return new A(); }
512 public B function g(B $x) { return $x; }
515 class XX {
517 public B $x;
519 public function __construct(B $x) {
520 $this->x = $x;
523 public bool function onstruct(A $x) {
524 $zz = $x->f($this->x);
525 $this->x = $zz;
526 return true;
532 class C1 {
535 class C2 {
536 public int function f() { return 0; }
539 class A {
540 C1 function f(C2 $x) { return $x; }
543 class B {
544 C1 function f(C2 $x) { return $x; }
545 bool function g(bool $x) { return true; }
548 bool function test(A $x, int $y) {
549 return true;
552 A function test2(B $x) {
553 $b = $x;
554 if(true) { $b = new A(); }
555 $zz = show($b);
556 return $b;
561 class A<T> {
563 private A<T> function f(T $x) {
564 $y = new A();
565 return $y;
569 // parameter substitution
570 class C<T> extends A<T> {
571 public T function get(T $x) {
572 $y = new A();
573 $this->f($x);
574 return $x;
576 private A<T> function f(T $x) {
577 return new A();
581 int function test() {
582 $x = new C();
583 return $x->get(0);