Rework interp-minstr logic in HHBBC
[hiphop-php.git] / hphp / test / slow / clsmeth / types.php
blobdd6ea3b43cf88dec4d3f3565f0ddbbf98f529570
1 <?hh
3 class K { const A = 0; const B = 1; }
4 class Foo { static function bar() {} }
6 function P(bool $b) { return $b ? "True\n" : "False\n"; }
7 function LV($x) { return __hhvm_intrinsics\launder_value($x); }
9 function is_as_static() {
10 $m = class_meth(Foo::class, 'bar');
12 echo '$m is AnyArray: ' .P($m is AnyArray);
13 echo '$m is shape(str,str): ' .P($m is shape(K::A => string, K::B => string));
14 echo '$m is shape(...): ' .P($m is shape(...));
15 echo '$m is Traversable: ' .P($m is Traversable);
16 echo '$m is Container: ' .P($m is Container);
17 echo '$m is (string,string): '.P($m is (string, string));
18 echo '$m[0] is string: ' .P($m[0] is string);
19 echo '$m[1] is string: ' .P($m[1] is string);
21 try { $m as AnyArray; } catch (Exception $e) { echo "Failed!\n"; }
22 try { $m as shape(K::A => string, K::B => string);
23 } catch (exception $e) { echo "shape!\n"; }
24 try { $m as shape(...); } catch (Exception $e) { echo "shape!\n"; }
25 try { $m as Traversable; } catch (Exception $e) { echo "Failed!\n"; }
26 try { $m as Container; } catch (Exception $e) { echo "Failed!\n"; }
27 try { $m as (string,string); } catch (Exception $e) { echo "Failed!\n"; }
28 try { $m[0] as string; } catch (Exception $e) { echo "Failed!\n"; }
29 try { $m[1] as string; } catch (Exception $e) { echo "Failed!\n"; }
31 var_dump(varray($m));
34 function is_as_dynamic() {
35 $m = LV(class_meth(Foo::class, 'bar'));
37 echo '$m is AnyArray: ' .P($m is AnyArray);
38 echo '$m is shape(str,str): ' .P($m is shape(K::A => string, K::B => string));
39 echo '$m is shape(...): ' .P($m is shape(...));
40 echo '$m is Traversable: ' .P($m is Traversable);
41 echo '$m is Container: ' .P($m is Container);
42 echo '$m is (string,string): '.P($m is (string, string));
43 echo '$m[0] is string: ' .P($m[0] is string);
44 echo '$m[1] is string: ' .P($m[1] is string);
46 try { $m as AnyArray; } catch (Exception $e) { echo "Failed!\n"; }
47 try { $m as shape(K::A => string, K::B => string);
48 } catch (exception $e) { echo "shape!\n"; }
49 try { $m as shape(...); } catch (Exception $e) { echo "shape!\n"; }
50 try { $m as Traversable; } catch (Exception $e) { echo "Failed!\n"; }
51 try { $m as Container; } catch (Exception $e) { echo "Failed!\n"; }
52 try { $m as (string,string); } catch (Exception $e) { echo "Failed!\n"; }
53 try { $m[0] as string; } catch (Exception $e) { echo "Failed!\n"; }
54 try { $m[1] as string; } catch (Exception $e) { echo "Failed!\n"; }
56 var_dump(varray($m));
59 function is_as_shuffle_static() {
60 $m = class_meth(Foo::class, 'bar');
62 if (is_array($m)) {
63 $x = varray($m);
64 echo '$m === varray($m): '.P($m === $x);
66 if ($m is Traversable) {
67 $x = $m as Traversable;
68 echo '$m === ($m as Traversable): '.P($m === $x);
69 } else {
70 echo "Failed \$m is Traversable!\n";
72 } else {
73 echo "Failed \$m is array!\n";
77 function is_as_shuffle_dynamic() {
78 $m = LV(class_meth(Foo::class, 'bar'));
80 if (is_array($m)) {
81 $x = varray($m);
82 echo '$m === varray($m): '.P($m === $x);
84 if ($m is AnyArray) {
85 $x = $m as Traversable;
86 echo '$m === ($m as AnyArray): '.P($m === $x);
87 } else {
88 echo "Failed \$m is AnyArray!\n";
90 } else {
91 echo "Failed \$m is array!\n";
95 <<__EntryPoint>>
96 function main() {
97 is_as_static(); is_as_static(); is_as_static();
98 is_as_dynamic(); is_as_dynamic(); is_as_dynamic();
99 is_as_shuffle_static(); is_as_shuffle_static(); is_as_shuffle_static();
100 is_as_shuffle_dynamic(); is_as_shuffle_dynamic(); is_as_shuffle_dynamic();