convert ***sort builtins to use inout instead of references
[hiphop-php.git] / hphp / test / slow / dynamic-calls / func / forbid-notice.php
blobd74daaccc1348704a4cd1713c6482708951c492c
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();
166 <<__DynamicallyConstructible>>
167 class F extends A {
170 async function positive_tests() {
171 try { $x = 'func'; $x(); } catch (Exception $e) { wrap($e); }
172 try { $x = 'async_func'; await $x(); } catch (Exception $e) { wrap($e); }
173 try { $x = 'A::func'; $x(); } catch (Exception $e) { wrap($e); }
174 try { $x = 'A::static_func'; $x(); } catch (Exception $e) { wrap($e); }
175 try { $x = 'A::async_func'; await $x(); } catch (Exception $e) { wrap($e); }
176 try { $x = 'A::static_async_func'; await $x(); } catch (Exception $e) { wrap($e); }
178 try { $x = ['A', 'func']; $x(); } catch (Exception $e) { wrap($e); }
179 try { $x = ['A', 'static_func']; $x(); } catch (Exception $e) { wrap($e); }
180 try { $x = ['A', 'async_func']; await $x(); } catch (Exception $e) { wrap($e); }
181 try { $x = ['A', 'static_async_func']; await $x(); } catch (Exception $e) { wrap($e); }
183 try { $x = [new A, 'func']; $x(); } catch (Exception $e) { wrap($e); }
184 try { $x = [new A, 'static_func']; $x(); } catch (Exception $e) { wrap($e); }
185 try { $x = [new A, 'async_func']; await $x(); } catch (Exception $e) { wrap($e); }
186 try { $x = [new A, 'static_async_func']; await $x(); } catch (Exception $e) { wrap($e); }
187 try { $x = [new C, 'foobar']; $x(); } catch (Exception $e) { wrap($e); }
189 try { $x = 'A'; $x::static_func(); } catch (Exception $e) { wrap($e); }
191 try { $x = 'A'; await $x::static_async_func(); } catch (Exception $e) { wrap($e); }
194 try { $x = 'static_func'; A::$x(); } catch (Exception $e) { wrap($e); }
196 try { $x = 'static_async_func'; await A::$x(); } catch (Exception $e) { wrap($e); }
199 A::positive_test1();
202 try { $x = 'A'; new $x(); } catch (Exception $e) { wrap($e); }
203 try { $obj = new A; $x = 'func'; $obj->$x(); } catch (Exception $e) { wrap($e); }
205 try { $obj = new A; $x = 'async_func'; await $obj->$x(); } catch (Exception $e) { wrap($e); }
207 try { $obj = new C; $x = 'foobar'; $obj->$x(); } catch (Exception $e) { wrap($e); }
209 try { array_map('func', [true]); } catch (Exception $e) { wrap($e); }
210 try { array_map('A::func', [true]); } catch (Exception $e) { wrap($e); }
211 try { array_map('A::static_func', [true]); } catch (Exception $e) { wrap($e); }
213 try { array_map(['A', 'func'], [true]); } catch (Exception $e) { wrap($e); }
214 try { array_map(['A', 'static_func'], [true]); } catch (Exception $e) { wrap($e); }
216 try { array_map([new A, 'func'], [true]); } catch (Exception $e) { wrap($e); }
217 try { array_map([new A, 'static_func'], [true]); } catch (Exception $e) { wrap($e); }
218 try { array_map([new C, 'foobar'], [true]); } catch (Exception $e) { wrap($e); }
220 $x = Vector::fromItems([[]]);
221 try { $x->map('func'); } catch (Exception $e) { wrap($e); }
223 try { $x->map('A::static_func'); } catch (Exception $e) { wrap($e); }
226 try { $x->map(['A', 'static_func']); } catch (Exception $e) { wrap($e); }
228 try { $x->map([new A, 'func']); } catch (Exception $e) { wrap($e); }
229 try { $x->map([new A, 'static_func']); } catch (Exception $e) { wrap($e); }
230 try { $x->map([new C, 'foobar']); } catch (Exception $e) { wrap($e); }
232 try { call_user_func('func'); } catch (Exception $e) { wrap($e); }
234 try { call_user_func('A::static_func'); } catch (Exception $e) { wrap($e); }
237 try { call_user_func(['A', 'static_func']); } catch (Exception $e) { wrap($e); }
239 try { call_user_func([new A, 'func']); } catch (Exception $e) { wrap($e); }
240 try { call_user_func([new A, 'static_func']); } catch (Exception $e) { wrap($e); }
241 try { call_user_func([new C, 'foobar']); } catch (Exception $e) { wrap($e); }
243 try { call_user_func_array('func', []); } catch (Exception $e) { wrap($e); }
245 try { call_user_func_array('A::static_func', []); } catch (Exception $e) { wrap($e); }
247 try { call_user_func_array(['A', 'static_func'], []); } catch (Exception $e) { wrap($e); }
248 try { call_user_func_array([new A, 'func'], []); } catch (Exception $e) { wrap($e); }
249 try { call_user_func_array([new A, 'static_func'], []); } catch (Exception $e) { wrap($e); }
251 try { $x = 'cmp'; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
253 try { $x = 'A::static_cmp'; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
256 try { $x = ['A', 'static_cmp']; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
258 try { $x = [new A, 'cmp']; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
259 try { $x = [new A, 'static_cmp']; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
260 try { $x = [new CCmp, 'foobar']; $y = [2, 1]; usort(inout $y, $x); } catch (Exception $e) { wrap($e); }
263 async function negative_tests() {
264 func();
265 count([]);
266 await async_func();
268 A::static_func();
270 await A::static_async_func();
272 Vector::fromItems([]);
274 $x = ($k ==> {});
275 $x(1);
277 A::negative_test1();
279 HH\class_meth(A::class, 'static_func')();
281 new A;
282 new Vector;
284 $obj = new A;
285 $obj->func();
287 await $obj->async_func();
290 $obj = new C;
291 $obj->foobar();
293 $obj = new Vector;
294 $obj->firstValue();
297 array_map($k ==> {}, [true]);
298 array_map(new Invokable, [true]);
300 $x = Vector::fromItems([true]);
301 $x->map($k ==> {});
302 $x->map(new Invokable);
304 $x = [2, 1];
305 usort(inout $x, ($k1, $k2) ==> { return $k1 <=> $k2; });
307 $x = [2, 1];
308 usort(inout $x, new InvokableCmp);
310 $x = 'count'; $x([]);
311 array_map('count', [[]]);
312 $x = Vector::fromItems([true]); $x->map('count');
313 call_user_func('count', []);
314 call_user_func_array('count', [[]]);
316 $x = 'HH\Vector::fromItems'; $x([]);
317 $x = ['HH\Vector', 'fromItems']; $x([]);
318 $x = [new Vector, 'fromItems']; $x([]);
319 $x = 'fromItems'; Vector::$x([]);
320 $x = [new Vector, 'firstValue']; $x();
321 $x = 'HH\Vector'; $x::fromItems([]);
322 $obj = new Vector; $x = 'firstValue'; $obj->$x();
324 array_map('HH\Vector::fromItems', [[]]);
325 array_map(['HH\Vector', 'fromItems'], [[]]);
326 array_map([new Vector, 'fromItems'], [[]]);
327 $x = Vector::fromItems([[]]);
328 $x->map('HH\Vector::fromItems');
329 $x->map(['HH\Vector', 'fromItems']);
330 $x->map([new Vector, 'fromItems']);
331 call_user_func('HH\Vector::fromItems', []);
332 call_user_func(['HH\Vector', 'fromItems'], []);
333 call_user_func([new Vector, 'firstValue']);
334 call_user_func([new Vector, 'fromItems'], []);
335 call_user_func_array('HH\Vector::fromItems', [[]]);
336 call_user_func_array(['HH\Vector', 'fromItems'], [[]]);
337 call_user_func_array([new Vector, 'firstValue'], []);
338 call_user_func_array([new Vector, 'fromItems'], [[]]);
340 $x = 'array_map';
341 $x('count', []);
343 $obj = null; $obj?->foobar();
345 idx('foobar', 'key');
347 $x = 'func2'; $x();
348 $x = 'async_func2'; await $x();
349 $x = 'A::func2'; $x();
350 $x = 'A::static_func2'; $x();
351 $x = 'A::async_func2'; await $x();
352 $x = 'A::static_async_func2'; await $x();
354 $x = ['A', 'func2']; $x();
355 $x = ['A', 'static_func2']; $x();
356 $x = ['A', 'async_func2']; await $x();
357 $x = ['A', 'static_async_func2']; await $x();
359 $x = [new A, 'func2']; $x();
360 $x = [new A, 'static_func2']; $x();
361 $x = [new A, 'async_func2']; await $x();
362 $x = [new A, 'static_async_func2']; await $x();
363 $x = [new E, 'foobar']; $x();
365 $x = 'A'; $x::static_func2();
367 $x = 'A'; await $x::static_async_func2();
370 $x = 'static_func2'; A::$x();
372 $x = 'static_async_func2'; await A::$x();
375 $x = 'F'; new $x();
376 $obj = new A; $x = 'func2'; $obj->$x();
378 $obj = new A; $x = 'async_func2'; await $obj->$x();
380 $obj = new E; $x = 'foobar'; $obj->$x();
382 array_map('func2', [true]);
383 array_map('A::func2', [true]);
384 array_map('A::static_func2', [true]);
386 array_map(['A', 'func2'], [true]);
387 array_map(['A', 'static_func2'], [true]);
389 array_map([new A, 'func2'], [true]);
390 array_map([new A, 'static_func2'], [true]);
391 array_map([new E, 'foobar'], [true]);
393 $x = Vector::fromItems([[]]);
394 $x->map('func2');
396 $x->map('A::static_func2');
399 $x->map(['A', 'static_func2']);
401 $x->map([new A, 'func2']);
402 $x->map([new A, 'static_func2']);
403 $x->map([new E, 'foobar']);
405 call_user_func('func2');
407 call_user_func('A::static_func2');
410 call_user_func(['A', 'static_func2']);
412 call_user_func([new A, 'func2']);
413 call_user_func([new A, 'static_func2']);
414 call_user_func([new E, 'foobar']);
416 call_user_func_array('func2', []);
418 call_user_func_array('A::static_func2', []);
420 call_user_func_array(['A', 'static_func2'], []);
421 call_user_func_array([new A, 'func2'], []);
422 call_user_func_array([new A, 'static_func2'], []);
424 $x = 'cmp2'; $y = [2, 1]; usort(inout $y, $x);
426 $x = 'A::static_cmp2'; $y = [2, 1]; usort(inout $y, $x);
429 $x = ['A', 'static_cmp2']; $y = [2, 1]; usort(inout $y, $x);
431 $x = [new A, 'cmp2']; $y = [2, 1]; usort(inout $y, $x);
432 $x = [new A, 'static_cmp2']; $y = [2, 1]; usort(inout $y, $x);
433 $x = [new CCmp2, 'foobar']; $y = [2, 1]; usort(inout $y, $x);
435 <<__EntryPoint>>
436 function main_entry(): void {
438 echo "=============== positive tests =====================\n";
439 HH\Asio\join(positive_tests());
441 echo "=============== negative tests =====================\n";
442 HH\Asio\join(negative_tests());
444 set_error_handler(
445 function ($type, $msg, $file) { throw new Exception($msg); }
447 echo "=============== positive tests (exceptions) ========\n";
448 HH\Asio\join(positive_tests());