convert ***sort builtins to use inout instead of references
[hiphop-php.git] / hphp / test / slow / dynamic-calls / inst_meth / forbid-throw.php
bloba5727bad537927b9d5cbb7060aa87da59743c021
1 <?hh
3 function wrap($e) { echo "Exception: {$e->getMessage()}\n"; }
5 function func() {}
6 async function async_func() { return 5; }
7 function cmp($x, $y) { return $x <=> $y; }
9 <<__DynamicallyCallable>> function func2() {}
10 <<__DynamicallyCallable>> async function async_func2() { return 5; }
11 <<__DynamicallyCallable>> function cmp2($x, $y) { return $x <=> $y; }
13 class D {
14 public function __call($a, $b) {}
18 class C extends D {
19 public function __call($a, $b) {}
36 class G {
37 <<__DynamicallyCallable>> public function __call($a, $b) {}
41 class E extends G {
42 <<__DynamicallyCallable>> public function __call($a, $b) {}
53 class CCmp {
54 public function __call($a, $b) { return $b[0] <=> $b[1]; }
58 class CCmp2 {
59 <<__DynamicallyCallable>> public function __call($a, $b) { return $b[0] <=> $b[1]; }
63 class Invokable {
64 public function __invoke() {}
67 class InvokableCmp {
68 public function __invoke($a, $b) { return $a <=> $b; }
71 class B {
72 public function func() {}
73 public static function static_func() {}
74 public async function async_func() { return 5; }
75 public static async function static_async_func() { return 5; }
77 <<__DynamicallyCallable>> public function func2() {}
78 <<__DynamicallyCallable>> public static function static_func2() {}
79 <<__DynamicallyCallable>> public async function async_func2() { return 5; }
80 <<__DynamicallyCallable>> public static async function static_async_func2() { return 5; }
83 class A extends B {
84 public function __construct() {}
86 public function func() {}
87 public async function async_func() { return 5; }
88 public function cmp($x, $y) { return $x <=> $y; }
89 public static function static_func() {}
90 public static async function static_async_func() { return 5; }
91 public static function static_cmp($x, $y) { return $x <=> $y; }
93 <<__DynamicallyCallable>> public function func2() {}
94 <<__DynamicallyCallable>> public async function async_func2() { return 5; }
95 <<__DynamicallyCallable>> public function cmp2($x, $y) { return $x <=> $y; }
96 <<__DynamicallyCallable>> public static function static_func2() {}
97 <<__DynamicallyCallable>> public static async function static_async_func2() { return 5; }
98 <<__DynamicallyCallable>> public static function static_cmp2($x, $y) { return $x <=> $y; }
100 public static async function positive_test1() {
106 $x = 'static_func';
107 try { self::$x(); } catch (Exception $e) { wrap($e); }
108 try { static::$x(); } catch (Exception $e) { wrap($e); }
109 try { parent::$x(); } catch (Exception $e) { wrap($e); }
116 $x = 'static_async_func';
117 try { await self::$x(); } catch (Exception $e) { wrap($e); }
118 try { await static::$x(); } catch (Exception $e) { wrap($e); }
119 try { await parent::$x(); } catch (Exception $e) { wrap($e); }
122 public static async function negative_test1() {
127 self::static_func();
128 static::static_func();
129 parent::static_func();
135 await self::static_async_func();
136 await static::static_async_func();
137 await parent::static_async_func();
139 new self;
140 new static;
141 new parent;
148 $x = 'static_func2';
149 self::$x();
150 static::$x();
151 parent::$x();
158 $x = 'static_async_func2';
159 await self::$x();
160 await static::$x();
161 await parent::$x();
165 <<__DynamicallyConstructible>>
166 class F extends A {
169 async function positive_tests() {
170 try { $x = 'func'; $x(); } catch (Exception $e) { wrap($e); }
171 try { $x = 'async_func'; await $x(); } catch (Exception $e) { wrap($e); }
172 try { $x = 'A::func'; $x(); } catch (Exception $e) { wrap($e); }
173 try { $x = 'A::static_func'; $x(); } catch (Exception $e) { wrap($e); }
174 try { $x = 'A::async_func'; await $x(); } catch (Exception $e) { wrap($e); }
175 try { $x = 'A::static_async_func'; await $x(); } catch (Exception $e) { wrap($e); }
177 try { $x = ['A', 'func']; $x(); } catch (Exception $e) { wrap($e); }
178 try { $x = ['A', 'static_func']; $x(); } catch (Exception $e) { wrap($e); }
179 try { $x = ['A', 'async_func']; await $x(); } catch (Exception $e) { wrap($e); }
180 try { $x = ['A', 'static_async_func']; await $x(); } catch (Exception $e) { wrap($e); }
182 try { $x = [new A, 'func']; $x(); } catch (Exception $e) { wrap($e); }
183 try { $x = [new A, 'static_func']; $x(); } catch (Exception $e) { wrap($e); }
184 try { $x = [new A, 'async_func']; await $x(); } catch (Exception $e) { wrap($e); }
185 try { $x = [new A, 'static_async_func']; await $x(); } catch (Exception $e) { wrap($e); }
186 try { $x = [new C, 'foobar']; $x(); } catch (Exception $e) { wrap($e); }
188 try { $x = 'A'; $x::static_func(); } catch (Exception $e) { wrap($e); }
190 try { $x = 'A'; await $x::static_async_func(); } catch (Exception $e) { wrap($e); }
193 try { $x = 'static_func'; A::$x(); } catch (Exception $e) { wrap($e); }
195 try { $x = 'static_async_func'; await A::$x(); } catch (Exception $e) { wrap($e); }
198 A::positive_test1();
201 try { $x = 'A'; new $x(); } catch (Exception $e) { wrap($e); }
202 try { $obj = new A; $x = 'func'; $obj->$x(); } catch (Exception $e) { wrap($e); }
204 try { $obj = new A; $x = 'async_func'; await $obj->$x(); } catch (Exception $e) { wrap($e); }
206 try { $obj = new C; $x = 'foobar'; $obj->$x(); } catch (Exception $e) { wrap($e); }
208 try { array_map('func', [true]); } catch (Exception $e) { wrap($e); }
209 try { array_map('A::func', [true]); } catch (Exception $e) { wrap($e); }
210 try { array_map('A::static_func', [true]); } catch (Exception $e) { wrap($e); }
212 try { array_map(['A', 'func'], [true]); } catch (Exception $e) { wrap($e); }
213 try { array_map(['A', 'static_func'], [true]); } catch (Exception $e) { wrap($e); }
215 try { array_map([new A, 'func'], [true]); } catch (Exception $e) { wrap($e); }
216 try { array_map([new A, 'static_func'], [true]); } catch (Exception $e) { wrap($e); }
217 try { array_map([new C, 'foobar'], [true]); } catch (Exception $e) { wrap($e); }
219 $x = Vector::fromItems([[]]);
220 try { $x->map('func'); } catch (Exception $e) { wrap($e); }
222 try { $x->map('A::static_func'); } catch (Exception $e) { wrap($e); }
225 try { $x->map(['A', 'static_func']); } catch (Exception $e) { wrap($e); }
227 try { $x->map([new A, 'func']); } catch (Exception $e) { wrap($e); }
228 try { $x->map([new A, 'static_func']); } catch (Exception $e) { wrap($e); }
229 try { $x->map([new C, 'foobar']); } catch (Exception $e) { wrap($e); }
231 try { call_user_func('func'); } catch (Exception $e) { wrap($e); }
233 try { call_user_func('A::static_func'); } catch (Exception $e) { wrap($e); }
236 try { call_user_func(['A', 'static_func']); } catch (Exception $e) { wrap($e); }
238 try { call_user_func([new A, 'func']); } catch (Exception $e) { wrap($e); }
239 try { call_user_func([new A, 'static_func']); } catch (Exception $e) { wrap($e); }
240 try { call_user_func([new C, 'foobar']); } catch (Exception $e) { wrap($e); }
242 try { call_user_func_array('func', []); } catch (Exception $e) { wrap($e); }
244 try { call_user_func_array('A::static_func', []); } catch (Exception $e) { wrap($e); }
246 try { call_user_func_array(['A', 'static_func'], []); } catch (Exception $e) { wrap($e); }
247 try { call_user_func_array([new A, 'func'], []); } catch (Exception $e) { wrap($e); }
248 try { call_user_func_array([new A, 'static_func'], []); } catch (Exception $e) { wrap($e); }
250 try { $x = 'cmp'; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
252 try { $x = 'A::static_cmp'; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
255 try { $x = ['A', 'static_cmp']; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
257 try { $x = [new A, 'cmp']; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
258 try { $x = [new A, 'static_cmp']; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
259 try { $x = [new CCmp, 'foobar']; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
262 async function negative_tests() {
263 func();
264 count([]);
265 await async_func();
267 A::static_func();
269 await A::static_async_func();
271 Vector::fromItems([]);
273 $x = ($k ==> {});
274 $x(1);
276 A::negative_test1();
278 HH\class_meth(A::class, 'static_func')();
280 new A;
281 new Vector;
283 $obj = new A;
284 $obj->func();
286 await $obj->async_func();
289 $obj = new C;
290 $obj->foobar();
292 $obj = new Vector;
293 $obj->firstValue();
296 array_map($k ==> {}, [true]);
297 array_map(new Invokable, [true]);
299 $x = Vector::fromItems([true]);
300 $x->map($k ==> {});
301 $x->map(new Invokable);
303 $x = [2, 1];
304 usort(inout $x, ($k1, $k2) ==> { return $k1 <=> $k2; });
306 $x = [2, 1];
307 usort(inout $x, new InvokableCmp);
309 $x = 'count'; $x([]);
310 array_map('count', [[]]);
311 $x = Vector::fromItems([true]); $x->map('count');
312 call_user_func('count', []);
313 call_user_func_array('count', [[]]);
315 $x = 'HH\Vector::fromItems'; $x([]);
316 $x = ['HH\Vector', 'fromItems']; $x([]);
317 $x = [new Vector, 'fromItems']; $x([]);
318 $x = 'fromItems'; Vector::$x([]);
319 $x = [new Vector, 'firstValue']; $x();
320 $x = 'HH\Vector'; $x::fromItems([]);
321 $obj = new Vector; $x = 'firstValue'; $obj->$x();
323 array_map('HH\Vector::fromItems', [[]]);
324 array_map(['HH\Vector', 'fromItems'], [[]]);
325 array_map([new Vector, 'fromItems'], [[]]);
326 $x = Vector::fromItems([[]]);
327 $x->map('HH\Vector::fromItems');
328 $x->map(['HH\Vector', 'fromItems']);
329 $x->map([new Vector, 'fromItems']);
330 call_user_func('HH\Vector::fromItems', []);
331 call_user_func(['HH\Vector', 'fromItems'], []);
332 call_user_func([new Vector, 'firstValue']);
333 call_user_func([new Vector, 'fromItems'], []);
334 call_user_func_array('HH\Vector::fromItems', [[]]);
335 call_user_func_array(['HH\Vector', 'fromItems'], [[]]);
336 call_user_func_array([new Vector, 'firstValue'], []);
337 call_user_func_array([new Vector, 'fromItems'], [[]]);
339 $x = 'array_map';
340 $x('count', []);
342 $obj = null; $obj?->foobar();
344 idx('foobar', 'key');
346 $x = 'func2'; $x();
347 $x = 'async_func2'; await $x();
348 $x = 'A::func2'; $x();
349 $x = 'A::static_func2'; $x();
350 $x = 'A::async_func2'; await $x();
351 $x = 'A::static_async_func2'; await $x();
353 $x = ['A', 'func2']; $x();
354 $x = ['A', 'static_func2']; $x();
355 $x = ['A', 'async_func2']; await $x();
356 $x = ['A', 'static_async_func2']; await $x();
358 $x = [new A, 'func2']; $x();
359 $x = [new A, 'static_func2']; $x();
360 $x = [new A, 'async_func2']; await $x();
361 $x = [new A, 'static_async_func2']; await $x();
362 $x = [new E, 'foobar']; $x();
364 $x = 'A'; $x::static_func2();
366 $x = 'A'; await $x::static_async_func2();
369 $x = 'static_func2'; A::$x();
371 $x = 'static_async_func2'; await A::$x();
374 $x = 'F'; new $x();
375 $obj = new A; $x = 'func2'; $obj->$x();
377 $obj = new A; $x = 'async_func2'; await $obj->$x();
379 $obj = new E; $x = 'foobar'; $obj->$x();
381 array_map('func2', [true]);
382 array_map('A::func2', [true]);
383 array_map('A::static_func2', [true]);
385 array_map(['A', 'func2'], [true]);
386 array_map(['A', 'static_func2'], [true]);
388 array_map([new A, 'func2'], [true]);
389 array_map([new A, 'static_func2'], [true]);
390 array_map([new E, 'foobar'], [true]);
392 $x = Vector::fromItems([[]]);
393 $x->map('func2');
395 $x->map('A::static_func2');
398 $x->map(['A', 'static_func2']);
400 $x->map([new A, 'func2']);
401 $x->map([new A, 'static_func2']);
402 $x->map([new E, 'foobar']);
404 call_user_func('func2');
406 call_user_func('A::static_func2');
409 call_user_func(['A', 'static_func2']);
411 call_user_func([new A, 'func2']);
412 call_user_func([new A, 'static_func2']);
413 call_user_func([new E, 'foobar']);
415 call_user_func_array('func2', []);
417 call_user_func_array('A::static_func2', []);
419 call_user_func_array(['A', 'static_func2'], []);
420 call_user_func_array([new A, 'func2'], []);
421 call_user_func_array([new A, 'static_func2'], []);
423 $x = 'cmp2'; $y = [2, 1]; usort(inout $y, $x);
425 $x = 'A::static_cmp2'; $y = [2, 1]; usort(inout $y, $x);
428 $x = ['A', 'static_cmp2']; $y = [2, 1]; usort(inout $y, $x);
430 $x = [new A, 'cmp2']; $y = [2, 1]; usort(inout $y, $x);
431 $x = [new A, 'static_cmp2']; $y = [2, 1]; usort(inout $y, $x);
432 $x = [new CCmp2, 'foobar']; $y = [2, 1]; usort(inout $y, $x);
434 <<__EntryPoint>> function main(): void {
435 echo "=============== positive tests =====================\n";
436 HH\Asio\join(positive_tests());
438 echo "=============== negative tests =====================\n";
439 HH\Asio\join(negative_tests());