language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
PHP
hhvm/hphp/hack/test/typecheck/assign_array_unresolved_bad.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test(bool $b, Vector<num> $x, Vector<arraykey> $y, string $z): void { if ($b) { $v = $x; } else { $v = $y; } // $v : Vector<num> | Vector<arraykey> and only values that are subtypes of // both num and arraykey can be appended to $v. $v[0] = $z; }
PHP
hhvm/hphp/hack/test/typecheck/assign_array_unresolved_bad2.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test( bool $b, Map<string, int> $x, Map<string, float> $y, num $z, ): void { if ($b) { $d = $x; } else { $d = $y; } $d['foo'] = $z; }
PHP
hhvm/hphp/hack/test/typecheck/assign_array_unresolved_good.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test1(bool $b, vec<int> $x, vec<string> $y, float $z): void { if ($b) { $v = $x; } else { $v = $y; } $v[0] = $z; hh_show($v); } function test2(bool $b, Vector<num> $x, Vector<arraykey> $y, int $z): void { if ($b) { $v = $x; } else { $v = $y; } // $v : Vector<num> | Vector<arraykey> and only values that are subtypes of // both num and arraykey can be appended to $v. $v[0] = $z; }
PHP
hhvm/hphp/hack/test/typecheck/assign_dict.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test(dict<string, int> $v): dict<arraykey, num> { $v[42] = 3.14; return $v; }
PHP
hhvm/hphp/hack/test/typecheck/assign_dict_element_property_bad.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class C { public vec<int> $vs = vec[]; } function test(dict<string, C> $d): void { $d['foo']->vs[0] = 'bar'; }
PHP
hhvm/hphp/hack/test/typecheck/assign_dict_element_property_good.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class C { public vec<string> $vs = vec[]; } function test(dict<string, C> $d): void { $d['foo']->vs[0] = 'bar'; }
PHP
hhvm/hphp/hack/test/typecheck/assign_key_refinement_completeness.php
<?hh <<__EntryPoint>> function main(): void { $v = 1 === 1 ? vec[0] : null; $v[($v as nonnull)[0]] = 42; echo $v[0]; }
PHP
hhvm/hphp/hack/test/typecheck/assign_key_refinement_soundness.php
<?hh <<__EntryPoint>> function main(): void { $v = vec[vec[0]]; $u = 1 === 2 ? vec[0] : null; $v[($u as nonnull)[0]][$u[0]] = 42; echo $v[0][0]; }
PHP
hhvm/hphp/hack/test/typecheck/assign_map_bad.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test(Map<string, int> $v): Map<string, num> { $v['foo'] = 3.14; return $v; }
PHP
hhvm/hphp/hack/test/typecheck/assign_map_element.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test(Map<string, vec<int>> $m): void { $m['foo'][0] = 'bar'; }
PHP
hhvm/hphp/hack/test/typecheck/assign_map_good.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test(Map<string, num> $v): Map<string, num> { $v['foo'] = 3.14; return $v; }
PHP
hhvm/hphp/hack/test/typecheck/assign_shape_field.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test(shape('x' => vec<int>) $s): shape('x' => vec<num>) { $s['x'][0] = 3.14; return $s; }
PHP
hhvm/hphp/hack/test/typecheck/assign_to_function_invocation.php
<?hh // strict function do_stuff(int $elapsed_time, int $start_time): void { $elapsed_time = Time::nowInMS() = $start_time; } class Time { public static function nowInMS():int { return 0; } }
PHP
hhvm/hphp/hack/test/typecheck/assign_tuple.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test((int, int) $t): (int, float) { $t[1] = 3.14; return $t; }
PHP
hhvm/hphp/hack/test/typecheck/assign_unresolved.php
<?hh // strict class Ref<T> { public function __construct(public T $value) {} } function test(bool $b): arraykey { if ($b) { $x = 42; } else { $x = 'foo'; } $r = new Ref(3.14); $r->value = $x; return $x; }
PHP
hhvm/hphp/hack/test/typecheck/assign_unresolved_class_get.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class A { public static num $x = 3.14; } class B { public static arraykey $x = 'foo'; } function test(bool $b): void { if ($b) { $c = A::class; } else { $c = B::class; } $c::$x = 42; }
PHP
hhvm/hphp/hack/test/typecheck/assign_unresolved_obj_get.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class C<T> { public function __construct(public T $value) {} } function test(bool $b, int $x, float $y, num $z): void { if ($b) { $xory = $x; } else { $xory = $y; } $c = new C($xory); $c->value = $z; }
hhvm/hphp/hack/test/typecheck/assign_unresolved_obj_get.php.tast_typecheck_exp
[(Fun { Aast.AnnotatedAST.f_annotation = (); f_mode = <opaque>; f_ret = (Some ([8:51-55], (Hprim Tvoid))); f_name = ([8:10-14], "\\test"); f_tparams = []; f_where_constraints = []; f_variadic = FVnonVariadic; f_params = [{ Aast.AnnotatedAST.param_annotation = ([8:20-22], bool); param_hint = (Some ([8:15-19], (Hprim Tbool))); param_is_variadic = false; param_pos = [8:20-22]; param_name = "$b"; param_expr = None; param_callconv = None; param_user_attributes = [] }; { Aast.AnnotatedAST.param_annotation = ([8:28-30], int); param_hint = (Some ([8:24-27], (Hprim Tint))); param_is_variadic = false; param_pos = [8:28-30]; param_name = "$x"; param_expr = None; param_callconv = None; param_user_attributes = [] }; { Aast.AnnotatedAST.param_annotation = ([8:38-40], float); param_hint = (Some ([8:32-37], (Hprim Tfloat))); param_is_variadic = false; param_pos = [8:38-40]; param_name = "$y"; param_expr = None; param_callconv = None; param_user_attributes = [] }; { Aast.AnnotatedAST.param_annotation = ([8:46-48], num); param_hint = (Some ([8:42-45], (Hprim Tnum))); param_is_variadic = false; param_pos = [8:46-48]; param_name = "$z"; param_expr = None; param_callconv = None; param_user_attributes = [] } ]; f_body = (NamedBody { Aast.AnnotatedAST.fnb_nast = [(If ((([9:7-9], bool), (Lvar ([9:7-9], $b))), [(Expr (([10:5-15], int), (Binop ((Eq None), (([10:5-10], int), (Lvar ([10:5-10], $xory))), (([10:13-15], int), (Lvar ([10:13-15], $x))))))) ], [(Expr (([12:5-15], float), (Binop ((Eq None), (([12:5-10], float), (Lvar ([12:5-10], $xory))), (([12:13-15], float), (Lvar ([12:13-15], $y))))))) ] )); (Expr (([14:3-20], C), (Binop ((Eq None), (([14:3-5], C), (Lvar ([14:3-5], $c))), (([14:8-20], C), (New ( (([14:12-13], C<_>), (CI (([14:12-13], "\\C"), []))), [(([14:14-19], (float | num | int)), (Lvar ([14:14-19], $xory)))], []))) )))); (Expr (([15:3-17], num), (Binop ((Eq None), (([15:3-12], (float | num | int)), (Obj_get ((([15:3-5], C), (Lvar ([15:3-5], $c))), (([15:7-12], (float | num | int)), (Id ([15:7-12], "value"))), OG_nullthrows))), (([15:15-17], num), (Lvar ([15:15-17], $z))))))) ]; fnb_unsafe = false }); f_fun_kind = FSync; f_user_attributes = []; f_ret_by_ref = false }); (Class { Aast.AnnotatedAST.c_annotation = (); c_mode = <opaque>; c_final = false; c_is_xhp = false; c_kind = Cnormal; c_name = ([4:7-8], "\\C"); c_tparams = <opaque>; c_extends = []; c_uses = []; c_xhp_attr_uses = []; c_xhp_category = []; c_req_extends = []; c_req_implements = []; c_implements = []; c_consts = []; c_typeconsts = []; c_static_vars = []; c_vars = [{ Aast.AnnotatedAST.cv_final = false; cv_is_xhp = false; cv_visibility = Public; cv_type = (Some ([5:38-39], (Habstr "T"))); cv_id = ([5:40-46], "value"); cv_expr = None; cv_user_attributes = [] } ]; c_constructor = (Some { Aast.AnnotatedAST.m_annotation = (); m_final = false; m_abstract = false; m_visibility = Public; m_name = ([5:19-30], "__construct"); m_tparams = []; m_where_constraints = []; m_variadic = FVnonVariadic; m_params = [{ Aast.AnnotatedAST.param_annotation = ([5:40-46], T); param_hint = (Some ([5:38-39], (Habstr "T"))); param_is_variadic = false; param_pos = [5:40-46]; param_name = "$value"; param_expr = None; param_callconv = None; param_user_attributes = [] } ]; m_body = (NamedBody { Aast.AnnotatedAST.fnb_nast = [(Expr (([5:40-46], T), (Binop ((Eq None), (([5:40-46], T), (Obj_get ((([5:40-46], <static>), This), (([5:40-46], T), (Id ([5:40-46], "value"))), OG_nullthrows))), (([5:40-46], T), (Lvar ([5:40-46], $value))))))); Noop]; fnb_unsafe = false }); m_fun_kind = FSync; m_user_attributes = []; m_ret = (Some ([5:19-30], (Happly (([5:19-30], "void"), [])))); m_ret_by_ref = false }); c_static_methods = []; c_methods = []; c_user_attributes = []; c_enum = None }) ] The TAST for this definition contains nodes which are not yet implemented. File "assign_unresolved_obj_get.php", line 14, characters 14-18: Unexpected type in TAST: expected (int | float), got (float | num | int) (TastTypecheck[11001])
PHP
hhvm/hphp/hack/test/typecheck/assign_vec.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test(vec<int> $v): vec<arraykey> { $v[0] = 'foo'; return $v; }
PHP
hhvm/hphp/hack/test/typecheck/assign_vector_bad.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test(Vector<string> $v): Vector<arraykey> { $v[0] = 42; return $v; }
PHP
hhvm/hphp/hack/test/typecheck/assign_vector_good.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test(Vector<arraykey> $v): Vector<arraykey> { $v[0] = 42; return $v; }
PHP
hhvm/hphp/hack/test/typecheck/assign_vec_property_bad.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class C { public vec<int> $vs = vec[]; } function test(C $c): void { $c->vs[0] = 'foo'; }
PHP
hhvm/hphp/hack/test/typecheck/assign_vec_property_good.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class C { public vec<string> $vs = vec[]; } function test(C $c): void { $c->vs[0] = 'foo'; }
PHP
hhvm/hphp/hack/test/typecheck/assing_array_get_pair_component_bad.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test(Pair<int, dict<string, int>> $p): void { $p[1]['foo'] = 42; }
PHP
hhvm/hphp/hack/test/typecheck/async_anon_function_explicit_return.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function foo(): Awaitable<int> { $x = async function() { return 5; }; return $x(); } function bar(): Awaitable<Awaitable<string>> { $p = async function() { $q = function() { $r = async function() { $s = function() { return "inception"; }; return $s(); }; return $r(); }; return $q(); }; return $p(); }
PHP
hhvm/hphp/hack/test/typecheck/async_anon_function_explicit_return_wrong_type.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function foo(): int { $x = async function() { return 5; }; return $x(); }
PHP
hhvm/hphp/hack/test/typecheck/async_awaitable.php
<?hh // (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. function makeVec(): vec<D> { return vec[]; } class D implements I { } interface I { } function makeAwaitable<T>(T $x): Awaitable<T> { throw new Exception("A"); } function test():void { $f = async () ==> makeVec(); // This works bar($f); // This also works bar<D>(async () ==> makeVec()); // As does this bar(() ==> makeAwaitable(makeVec())); // This doesn't, when pessimised bar(async () ==> makeVec()); } function bar<T as I>((function(): Awaitable<vec<T>>) $fn):void { }
PHP
hhvm/hphp/hack/test/typecheck/async_block1.php
<?hh async function g(): Awaitable<int> { return 1; } async function f(): Awaitable<int> { $q = async { $a = await g(); return $a; }; return await $q; } function h(): Awaitable<int> { return async { return 1; }; } function main(): void { $a = async { return 1; }; }
PHP
hhvm/hphp/hack/test/typecheck/async_block2.php
<?hh // strict async function g(): Awaitable<int> { return 1; } async function f(): Awaitable<string> { $q = async { $a = await g(); return $a; }; return await $q; }
PHP
hhvm/hphp/hack/test/typecheck/async_block3.php
<?hh // strict async function f(): Awaitable<string> { $x = () ==> async { return 'foo'; }; return await $x(); }
PHP
hhvm/hphp/hack/test/typecheck/async_block4.php
<?hh // strict async function f(): Awaitable<string> { /* HH_FIXME[1002]: check parser error recovery */ $x = () ==> async { return 10; }; return await $x(); }
PHP
hhvm/hphp/hack/test/typecheck/async_function_explicit_null_return_wrong_type.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function foo(): Awaitable<void> { return; } async function foo_error(): void { return; }
PHP
hhvm/hphp/hack/test/typecheck/async_function_explicit_return.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function foo<T>(T $x): Awaitable<T> { return $x; } class Baz { public static async function foo(): Awaitable<string> { return "hello"; } } async function sun<T>(T $x): Awaitable<Awaitable<T>> { return foo($x); } async function bar(): Awaitable<mixed> { if (true) { return 5; } return "hello"; }
PHP
hhvm/hphp/hack/test/typecheck/async_function_explicit_return_nothing.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function foo(): Awaitable<void> { return; }
PHP
hhvm/hphp/hack/test/typecheck/async_function_explicit_return_type_error.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function foo<T>(T $x): Awaitable<T> { return $x; } async function foo_error<T>(T $x): T { return $x; }
PHP
hhvm/hphp/hack/test/typecheck/async_function_implicit_return.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function foo(): Awaitable<void> { }
PHP
hhvm/hphp/hack/test/typecheck/async_function_implicit_return2.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function coin_flip(): bool { return false; } async function gen_f2(Awaitable<void> $a, Awaitable<void> $b): Awaitable<void> { if (coin_flip()) { return await $a; } if (coin_flip()) { return await $b; } // Implicit return null in an async function is compatible with // Awaitable<void> }
PHP
hhvm/hphp/hack/test/typecheck/async_function_implicit_return_wrong_type.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function foo(): void { }
PHP
hhvm/hphp/hack/test/typecheck/async_function_implicit_return_wrong_type2.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function f(): Awaitable<int> { if (condition()) { return 1; } } function condition(): bool { return true; }
PHP
hhvm/hphp/hack/test/typecheck/async_function_implicit_return_wrong_type3.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function coin_flip(): bool { return false; } function f(Awaitable<void> $a, Awaitable<void> $b): Awaitable<void> { if (coin_flip()) { return $a; } if (coin_flip()) { return $b; } // Implicit return null in a normal function is not compatible with // Awaitable<void> }
PHP
hhvm/hphp/hack/test/typecheck/async_function_return_types_are_infectious.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function foo() : Awaitable<string> { return "blah"; } function bar() : Awaitable<string> { return foo(); }
PHP
hhvm/hphp/hack/test/typecheck/async_function_untyped1.php
<?hh async function f() /* : TAny */ { return 10; } function test(): int { $x = 10; if (f()) { $x = 20; } return $x; }
PHP
hhvm/hphp/hack/test/typecheck/async_function_untyped2.php
<?hh class C { public static async function f() /* : TAny */ { return 10; } } function test(): int { $x = 10; if (C::f()) { $x = 20; } return $x; }
PHP
hhvm/hphp/hack/test/typecheck/async_function_untyped3.php
<?hh function takes_int(int $x): void {} async function f() /* : TAny */ { return 10; } function test(): int { $val = f(); takes_int($val); return $val; }
PHP
hhvm/hphp/hack/test/typecheck/async_function_untyped4.php
<?hh interface I1 { public function f(): int; } class C1 implements I1 { public async function f() /* : TAny */ { return 10; } }
PHP
hhvm/hphp/hack/test/typecheck/async_function_untyped5.php
<?hh class C1 { public async function f() /* : TAny */ { return 10; } } class C2 extends C1 { public function f(): int { return 10; } }
PHP
hhvm/hphp/hack/test/typecheck/async_function_untyped6.php
<?hh class C { public async function f() /* : TAny */ { return 10; } } function test(): int { $inst = new C(); $x = 10; if (!$inst->f()) { $x = 20; } return $x; }
PHP
hhvm/hphp/hack/test/typecheck/async_hint2.php
<?hh class Foo { // Testing method public async function wrong_hint(): int { throw new Exception(); } }
PHP
hhvm/hphp/hack/test/typecheck/async_hint4.php
<?hh class C {} class Foo { // Testing method public async function wrong_hint(): C { throw new Exception(); } }
PHP
hhvm/hphp/hack/test/typecheck/async_hint5.php
<?hh // Testing lambda async function foo(): Awaitable<void> { $nohint = async $x ==> await $x + 1; throw new Exception(); }
PHP
hhvm/hphp/hack/test/typecheck/async_hint6.php
<?hh // Testing function async function right_hint(): Awaitable<int> { throw new Exception(); } // Testing function async function no_hint() { throw new Exception(); }
PHP
hhvm/hphp/hack/test/typecheck/async_hint7.php
<?hh class Foo { // Testing method public async function right_hint(): Awaitable<int> { throw new Exception(); } // Testing method public async function no_hint() { throw new Exception(); } }
PHP
hhvm/hphp/hack/test/typecheck/async_last.php
<?hh // strict class Foo { // these will be fine public static async function bar(): Awaitable<void> {} public static function bar2(): void {} // this one will cause an error because async is not last public async static function baz(): Awaitable<void> {} }
PHP
hhvm/hphp/hack/test/typecheck/async_override_bad.php
<?hh // (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. class C { public async function foo():Awaitable<int> { return 3; } public function boo():Awaitable<int> { return $this->foo(); } } class D extends C { public async function bar():Awaitable<int> { return 4; } // Illegal: do not permit non-async methods to override async ones public function foo():Awaitable<int> { return $this->bar(); } // Legal: allow async methods to override non-async ones public async function boo():Awaitable<int> { return 5; } }
PHP
hhvm/hphp/hack/test/typecheck/attr_children.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function test(): void { $x = <xx children=""/>; } class :xx extends XHPTest { attribute string children; }
PHP
hhvm/hphp/hack/test/typecheck/awaitable_subtype_error.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function genFoo(): Awaitable<int> { return 123; } async function genBar(): Awaitable<string> { return await genFoo(); }
PHP
hhvm/hphp/hack/test/typecheck/awaitable_yield_result_error.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function foo(): Awaitable<?int> { return null; } async function foo_error(): ?int { return null; }
PHP
hhvm/hphp/hack/test/typecheck/awaitable_yield_result_noerror1.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function foo(): Awaitable<void> { return; }
PHP
hhvm/hphp/hack/test/typecheck/awaitable_yield_waitfor_error.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function foo(): void { $bar = await SomePreparable::gen(); } class SomePreparable { public static async function gen(): Awaitable<int> { return 0; } }
PHP
hhvm/hphp/hack/test/typecheck/awaitable_yield_waitfor_noerror1.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function foo(): Awaitable<void> { $bar = await SomePreparable::gen(); } class SomePreparable { public static async function gen(): Awaitable<int> { return 0; } }
PHP
hhvm/hphp/hack/test/typecheck/await_intersection.php
<?hh async function test(?Awaitable<mixed> $x): Awaitable<void> { if ($x !== null) { await $x; } }
PHP
hhvm/hphp/hack/test/typecheck/await_in_expressions10.php
<?hh // strict async function f1(Awaitable<int> $a): Awaitable<void> { $b = 10 |> f(await $a, $$); } function f(int $a, int $b): int { return $a; }
PHP
hhvm/hphp/hack/test/typecheck/await_in_expressions2.php
<?hh // strict async function f1(Awaitable<int> $a): Awaitable<void> { $x = 1; $b = ($x = await $a); }
PHP
hhvm/hphp/hack/test/typecheck/await_in_expressions3.php
<?hh // strict async function f1(Awaitable<int> $a): Awaitable<void> { f2(await $a); } function f2(int $x): int { return $x; }
PHP
hhvm/hphp/hack/test/typecheck/await_in_expressions4.php
<?hh // strict async function f1(Awaitable<int> $a): Awaitable<void> { // currently not an error, but should be $c = (await $a); }
PHP
hhvm/hphp/hack/test/typecheck/await_in_expressions5.php
<?hh // strict async function f1(Awaitable<int> $a): Awaitable<void> { while ((await $a) > 1) { } }
PHP
hhvm/hphp/hack/test/typecheck/await_in_expressions6.php
<?hh // strict async function f1(Awaitable<int> $a): Awaitable<void> { do { } while (await $a); }
PHP
hhvm/hphp/hack/test/typecheck/await_in_expressions7.php
<?hh // strict async function f1(Awaitable<int> $a): Awaitable<void> { $x = 1; switch ($x) { case await $a: { } } }
PHP
hhvm/hphp/hack/test/typecheck/await_in_expressions9.php
<?hh // strict async function f1(Awaitable<int> $a): Awaitable<void> { $b = (await $a) |> f($$); } function f(int $a): int { return $a; }
PHP
hhvm/hphp/hack/test/typecheck/await_in_statements.php
<?hh // strict async function f(Awaitable<int> $a): Awaitable<int> { await $a; $b = await $a; return await $a; }
PHP
hhvm/hphp/hack/test/typecheck/await_in_sync_lambda.php
//// file1.php <?hh async function gen(): Awaitable<void> {} //// file2.php <?hh // Copyright 2004-present Facebook. All Rights Reserved. function call((function(): void) $f): void { $f(); } function test(): void { call(() ==> await gen()); }
PHP
hhvm/hphp/hack/test/typecheck/await_on_async_function.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function fetch_db_results(): Awaitable<string> { return "Results!!!"; } async function return_db_results(): Awaitable<string> { $a = await fetch_db_results(); return "the results are".$a; }
PHP
hhvm/hphp/hack/test/typecheck/await_on_awaitable.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function slow_print(Awaitable<string> $x): Awaitable<void> { $a = await $x; display($a); } function display(string $y): void { print $y; }
PHP
hhvm/hphp/hack/test/typecheck/await_on_awaitable_type_mismatch.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function plus_three(Awaitable<string> $x): Awaitable<int> { $a = await $x; return 3 + $a; }
PHP
hhvm/hphp/hack/test/typecheck/await_on_illegal_value.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function f(): void { await 42; }
PHP
hhvm/hphp/hack/test/typecheck/await_on_unresolved.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function something_complex( Awaitable<int> $i, Awaitable<string> $s, ): Awaitable<void> { if (true) { $v = $i; } else { $v = $s; } $z = await $v; }
PHP
hhvm/hphp/hack/test/typecheck/await_preserves_nullability.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ class Foo<T as arraykey> { public async function print_if_possible( ?Awaitable<T> $blah, ): Awaitable<void> { $x = await $blah; $this->doer($x); } private function doer(T $item): void { if ($item) { print $item; } } }
PHP
hhvm/hphp/hack/test/typecheck/await_twice.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ async function tweedledum(): Awaitable<string> { return "alice"; } async function tweedledee(): Awaitable<Awaitable<string>> { return tweedledum(); } async function whats_in_the_rabbit_hole(): Awaitable<void> { $a = await tweedledee(); $b = await $a; print($b); }
PHP
hhvm/hphp/hack/test/typecheck/backtick_xhp.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ final class :ui:link extends XHPTest {} class Bloo { public function mybloo(): void { $x = <ui:link>abcd `</ui:link>; } }
PHP
hhvm/hphp/hack/test/typecheck/bad_contra_pos_test.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. abstract class B<-T> {} interface I {} function toprun<T>(B<T> $rule, T $rule_input): void {} function toprunI(B<I> $rule, I $rule_input): void {} // Derived class final class D extends B<I> {} final class TestClass { private ?I $mv; public static function run<T>(B<T> $rule, T $rule_input): void {} public function test(): void { // The first two should give similar errors to the last of these self::run(new D(), $this->mv); // toprun(new D(), $this->mv); // toprunI(new D(), $this->mv); } }
PHP
hhvm/hphp/hack/test/typecheck/bad_decl_override.php
////file1.php <?hh enum E : int { A = 3; } interface I { abstract const vec<E> VALS; } ////file2.php <?hh class C implements I { const vec<int> VALS = vec[3]; }
PHP
hhvm/hphp/hack/test/typecheck/bad_function_hint.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function f(): function():int { return () ==> 1; }
PHP
hhvm/hphp/hack/test/typecheck/bad_function_hint2.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function f(): (function():int, int) { return tuple(() ==> 1, 1); }
PHP
hhvm/hphp/hack/test/typecheck/bad_type_structure_array.php
<?hh // strict function concrete(TypeStructure<varray<int>> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['generic_types']); // any other field will fail hh_show($ts['classname']); hh_show($ts['nullable']); hh_show($ts['elem_types']); hh_show($ts['fields']); hh_show($ts['param_types']); hh_show($ts['return_type']); // make sure kind still works hh_show($ts['kind']); } function generic<T as varray<int>>(TypeStructure<T> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['generic_types']); // any other field will fail hh_show($ts['classname']); hh_show($ts['nullable']); hh_show($ts['elem_types']); hh_show($ts['fields']); hh_show($ts['param_types']); hh_show($ts['return_type']); // make sure kind still works hh_show($ts['kind']); }
PHP
hhvm/hphp/hack/test/typecheck/bad_type_structure_class.php
<?hh // strict class C<T> {} function concrete(TypeStructure<C<int>> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['classname']); hh_show($ts['generic_types']); // any other field will fail hh_show($ts['nullable']); hh_show($ts['elem_types']); hh_show($ts['fields']); hh_show($ts['param_types']); hh_show($ts['return_type']); // make sure kind still works hh_show($ts['kind']); } function generic<T as C<int>>(TypeStructure<T> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['classname']); hh_show($ts['generic_types']); // any other field will fail hh_show($ts['nullable']); hh_show($ts['elem_types']); hh_show($ts['fields']); hh_show($ts['param_types']); hh_show($ts['return_type']); // make sure kind still works hh_show($ts['kind']); }
PHP
hhvm/hphp/hack/test/typecheck/bad_type_structure_function.php
<?hh // strict function concrete(TypeStructure<(function(int): arraykey)> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['param_types']); hh_show($ts['return_type']); // any other field will fail hh_show($ts['classname']); hh_show($ts['nullable']); hh_show($ts['elem_types']); hh_show($ts['fields']); hh_show($ts['generic_types']); // make sure kind still works hh_show($ts['kind']); } function generic<T as (function(): arraykey)>(TypeStructure<T> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['param_types']); hh_show($ts['return_type']); // any other field will fail hh_show($ts['classname']); hh_show($ts['nullable']); hh_show($ts['elem_types']); hh_show($ts['fields']); hh_show($ts['generic_types']); // make sure kind still works hh_show($ts['kind']); }
PHP
hhvm/hphp/hack/test/typecheck/bad_type_structure_nullable.php
<?hh // strict function concrete(TypeStructure<?num> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['nullable']); // any other field will fail hh_show($ts['classname']); hh_show($ts['elem_types']); hh_show($ts['fields']); hh_show($ts['param_types']); hh_show($ts['return_type']); hh_show($ts['generic_types']); // make sure kind still works hh_show($ts['kind']); } function generic<T as ?num>(TypeStructure<T> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['nullable']); // any other field will fail hh_show($ts['classname']); hh_show($ts['elem_types']); hh_show($ts['fields']); hh_show($ts['param_types']); hh_show($ts['return_type']); hh_show($ts['generic_types']); // make sure kind still works hh_show($ts['kind']); }
PHP
hhvm/hphp/hack/test/typecheck/bad_type_structure_primitive.php
<?hh // strict function concrete(TypeStructure<int> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); // any other field will fail hh_show($ts['classname']); hh_show($ts['nullable']); hh_show($ts['elem_types']); hh_show($ts['fields']); hh_show($ts['param_types']); hh_show($ts['return_type']); hh_show($ts['generic_types']); // make sure kind still works hh_show($ts['kind']); } function generic<T as int>(TypeStructure<T> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); // any other field will fail hh_show($ts['classname']); hh_show($ts['nullable']); hh_show($ts['elem_types']); hh_show($ts['fields']); hh_show($ts['param_types']); hh_show($ts['return_type']); hh_show($ts['generic_types']); // make sure kind still works hh_show($ts['kind']); }
PHP
hhvm/hphp/hack/test/typecheck/bad_type_structure_shape.php
<?hh // strict function concrete(TypeStructure<shape(...)> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['fields']); // any other field will fail hh_show($ts['classname']); hh_show($ts['nullable']); hh_show($ts['elem_types']); hh_show($ts['param_types']); hh_show($ts['return_type']); hh_show($ts['generic_types']); // make sure kind still works hh_show($ts['kind']); } function generic<T as shape(...)>(TypeStructure<T> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['fields']); // any other field will fail hh_show($ts['classname']); hh_show($ts['nullable']); hh_show($ts['elem_types']); hh_show($ts['param_types']); hh_show($ts['return_type']); hh_show($ts['generic_types']); // make sure kind still works hh_show($ts['kind']); }
PHP
hhvm/hphp/hack/test/typecheck/bad_type_structure_tuple.php
<?hh // strict function concrete(TypeStructure<(arraykey, ?num)> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['elem_types']); // any other field will fail hh_show($ts['classname']); hh_show($ts['nullable']); hh_show($ts['fields']); hh_show($ts['param_types']); hh_show($ts['return_type']); hh_show($ts['generic_types']); // make sure kind still works hh_show($ts['kind']); } function generic<T as (arraykey, ?num)>(TypeStructure<T> $ts): void { hh_show($ts['kind']); hh_show($ts['alias']); hh_show($ts['name']); hh_show($ts['elem_types']); // any other field will fail hh_show($ts['classname']); hh_show($ts['nullable']); hh_show($ts['fields']); hh_show($ts['param_types']); hh_show($ts['return_type']); hh_show($ts['generic_types']); // make sure kind still works hh_show($ts['kind']); }
PHP
hhvm/hphp/hack/test/typecheck/binint.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function foo(): int { return 0b020; }
PHP
hhvm/hphp/hack/test/typecheck/bitwisenot.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function int_not(int $a): int { return ~$a; } function generic_int_not<T as int>(T $a): int { return ~$a; } enum Colour: int as int { Red = 0; Blue = 1; } function enum_not(Colour $a): int { return ~$a; }
PHP
hhvm/hphp/hack/test/typecheck/bitwisenot_bad.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function foo(bool $a): bool { return ~$a; }
PHP
hhvm/hphp/hack/test/typecheck/bug_union_call.php
<?hh function test(bool $b, Map<int, int> $n): void { if ($b) { $m = ($b ? null : $n); } else { $m = Map {0 => false}; } $m?->get(0); }
PHP
hhvm/hphp/hack/test/typecheck/bug_union_inter1.php
<?hh function test(): void { (Map {'a' => 0})->map( $value ==> { if ($value is string || $value is bool) { return (string) $value; } return ''; } ); }
PHP
hhvm/hphp/hack/test/typecheck/call_fty_any.php
<?hh // Copyright 2004-present Facebook. All Rights Reserved. class A { public /* TAny */ $foo; public function test(): void { $x = Vector {}; $this->foo->bar($x); $x[0][1]; } }
PHP
hhvm/hphp/hack/test/typecheck/call_generic.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test1<T as (function(): void)>(T $f): void { $f(); } class C {} function test2<T as (function(): void) as C>(T $f): void { $f(); }
PHP
hhvm/hphp/hack/test/typecheck/call_generic_multiple_bounds_1.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. interface I { } interface J { } function test<T as (function(): I) as (function(): J)>(T $f): I { $x = $f(); return $x; } function test2<T as (function(): I) as (function(): J)>(T $f): I { // Test bidirectional type checking: we should not attempt to use I // when checking $f() return $f(); } function test3<T as (function(): I) as (function(): J)>(T $f): J { $x = $f(); return $x; } function test4<T as (function(): I) as (function(): J)>(T $f): J { // Test bidirectional type checking: we should not attempt to use J // when checking $f() return $f(); }
PHP
hhvm/hphp/hack/test/typecheck/call_generic_multiple_bounds_2.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test<T as (function(int): void) as (function(float): void)>(num $x, T $f): string { return $f($x); }
PHP
hhvm/hphp/hack/test/typecheck/call_in_static_darray.php
<?hh class C { public static function f(): string { return "lol"; } public static darray<string, string> $x = darray['a' => C::f()]; }