Disallow ... without type in function typehints
[hiphop-php.git] / hphp / hack / test / typecheck / meth_caller6.php
blob263ed25e0b40fefb86d51abb7357c4d5e6284729
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 abstract class E {
13 public function foo(): void {}
16 final class A<T as E> {
18 public function __construct((function(T): void) $x) {}
22 function test1<T as E>(): A<T> {
23 return new A(meth_caller('E', 'foo'));
26 function test2<T as E>(): A<T> {
27 // Type of $f should be
28 // function(E):void
29 $f = meth_caller(E::class, 'foo');
30 // Now type of $r should be
31 // A<x>
32 // with constraint that
33 // x <: E
34 // function(E):void <: function(x):void
35 // i.e.
36 // x <: E (contravariance), so we're ok
37 $r = new A($f);
38 // Now we need to check the return type
39 // A<x> <: A<T>
40 // So by invariance we have x=T, and we're ok
41 // because of the T as E constraint
42 return $r;