Disallow ... without type in function typehints
[hiphop-php.git] / hphp / hack / test / typecheck / arraykey_type_hint.php
blobba78a4764d50f17a4ec148aa2aa9d1a741778157
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 function f(arraykey $k1, arraykey $k2): arraykey {
13 return $k1;
16 function generic<T as arraykey>(T $k1, T $k2): T {
17 return $k2;
20 function cast(arraykey $k1, arraykey $k2): (string, int) {
21 return tuple((string)$k1, (int)$k2);
24 function f_opt(?arraykey $k1, arraykey $k2): arraykey {
25 if (null === $k1) {
26 return 0;
28 return f($k1, $k2);
31 abstract class C {}
32 function get_classname(): classname<C> {
33 return C::class;
36 function test(): void {
37 f(1, 1);
38 f('a', 'a');
39 f(1, 'a');
40 f('a', 1);
41 f(get_classname(), C::class);
43 generic(1, 1);
44 generic('a', 'a');
45 generic(get_classname(), get_classname());
47 f_opt(1, 1);
48 f_opt('a', 'a');
49 f_opt('a', 1);
50 f_opt(1, 'a');
51 f_opt(null, 1);
52 f_opt(null, 'a');
55 function test_switch(arraykey $x): bool {
56 $c = 1;
57 if ($c == $x) {
58 return true;
61 if (0 === $x) {
62 return true;
65 if ('' === $x) {
66 return true;
69 switch ($x) {
70 case $c:
71 return true;
72 case 'a':
73 $res = false;
74 break;
75 case 3:
76 $res = true;
77 break;
78 default:
79 $res = true;
81 return $res;