language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
PHP
hhvm/hphp/hack/test/lint/valid_interface_equality_check2.php
<?hh // strict interface A {} class C {} class D extends C implements A {} function test(A $a, C $c): void { // It is possible for this comparison to evaluate to true even though there is // no subtyping relationship between A and C, since D exists. // We don't have a simple way of determining whether such a class exists at // lint time, so we don't warn about comparisons involving an interface type. if ($a === $c) { var_dump($a); } }
PHP
hhvm/hphp/hack/test/lint/valid_null_check.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function expect_int(int $_): void {} function test(?int $x): void { if ($x !== null) { expect_int($x); } }
PHP
hhvm/hphp/hack/test/lint/xhp_hack_error1.php
<?hh // Copyright 2004-present Facebook. All Rights Reserved. final class :derpyclass { protected function renderMeDerpy() { $select = <select name={$this->:name} />; $select->appendChild( <option value={$default} selected={XhpHackError::attributeExpectsBool("selected")}> Custom ({$default}) </option>); return null; } }
PHP
hhvm/hphp/hack/test/lint/xhp_hack_error2.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class :reallyderpyclass { protected function renderMeRealDerpy(): :xhp { return <ui:page-header label={XhpHackError ::clownyCastStringish(RecoveryExistingSessionText ::checkYourNotifications())} />; } }
PHP
hhvm/hphp/hack/test/lint/xhp_invalid_attr_value.php
<?hh // Copyright 2004-present Facebook. All Rights Reserved. class :foo extends XHPTest implements XHPChild { attribute enum {'big', 'small'} size; } function bad_attr_value(): void { $x = <foo size="medium" />; }
PHP
hhvm/hphp/hack/test/lint/xhp_invalid_attr_value_int.php
<?hh // Copyright 2004-present Facebook. All Rights Reserved. class :foo extends XHPTest implements XHPChild { attribute enum {1, 2} size; } function bad_attr_value(): void { $x = <foo size={3} />; }
PHP
hhvm/hphp/hack/test/lint/xhp_invalid_attr_value_int_and_string.php
<?hh // Copyright 2004-present Facebook. All Rights Reserved. class :foo extends XHPTest implements XHPChild { attribute enum {1, "stuff"} bar; } function bad_attr_value(): void { $x = <foo bar={3} />; }
PHP
hhvm/hphp/hack/test/lint/implicit_pess/awaitable_awaitable_bad.php
<?hh async function awaitable_awaitable_bad1(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], // should not trigger ASYNC_AWAIT_LAMBDA, but should trigger AWAITABLE_AWAITABLE async $x ==> awaitable_awaitable_bad1($x), // should trigger rule ); } async function awaitable_awaitable_bad2(int $x): Awaitable<void> { $f = async (int $x, int $y) ==> awaitable_awaitable_bad2($x + $y); $_ = await $f(0, 0); }
PHP
hhvm/hphp/hack/test/lint/implicit_pess/awaitable_awaitable_good.php
<?hh async function awaitable_awaitable_good1(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], async $x ==> await awaitable_awaitable_good1($x), // should not trigger rule ); } async function awaitable_awaitable_good2(int $x): Awaitable<void> { // annotated inline lambda, should not trigger rule $_ = await HH\Lib\Vec\map_async( vec[], async ($x): Awaitable<Awaitable<void>> ==> awaitable_awaitable_good2($x), ); } async function awaitable_awaitable_good3(int $x): Awaitable<void> { $_ = await HH\Lib\Vec\map_async( vec[], // no nested Awaitable here $x ==> { return awaitable_awaitable_good3($x); }, ); } async function gen_map<Ta, Tb>( Traversable<Ta> $_, (function(Ta): Awaitable<Tb>) $_, ): Awaitable<Vector<Tb>> { return Vector {}; } async function awaitable_awaitable_good4(int $x): Awaitable<void> { // compound lambda with Awaitable<T>, should not trigger rule $candidate_ids = vec[1, 2, 3, 4, 5]; $_ = await gen_map( $candidate_ids, async ($candidate_id) ==> { return Pair {$candidate_id, 0.0}; }, ); } async function awaitable_awaitable_good5(int $x): Awaitable<void> { // annotated compound lambda, should not trigger rule $f = async (int $x): Awaitable<Awaitable<void>> ==> { $y = 1; if ($x === 2) { return awaitable_awaitable_good5($x); } else { return awaitable_awaitable_good5($x + $y); } }; $_ = await $f(0); }
PHP
hhvm/hphp/hack/test/lint/implicit_pess/awaitable_like_awaitable.php
<?hh interface I {} function foo(I $i): void { async () ==> gen($i); } async function gen(I $vc): Awaitable<void> {}
PHP
hhvm/hphp/hack/test/lint/implicit_pess/cast_non_primitive_bad.php
<?hh final class C {} final class D {} final class E {} final class F {} function cast_non_primitive_bad1(): void { (int) (Vector {}); } function cast_non_primitive_bad2(): void { (int) (vec[]); } function cast_non_primitive_bad3(): void { (int) (new C()); } function test_non_primitive_bad4(bool $test): void { if ($test) { $x = 'test'; } else { $x = vec[]; } (int) $x; } function test_non_primitive_bad5(bool $test): void { if ($test) { $x = 'test'; } else { $x = new C(); } (int) $x; } function cast_non_primitive_bad6(bool $test): void { if ($test) { $x = vec[]; } else { $x = new C(); } (int) $x; } function cast_non_primitive_bad7(Stringish $test): void { (int) $test; } function cast_non_primitive_bad8( bool $test1, bool $test2, bool $test3, ): void { if ($test1) { $a = new C(); } else { $a = new D(); } if ($test2) { $b = new E(); } else { $b = new F(); } if ($test3) { $c = $a; } else { $c = $b; } (int) $c; } function cast_non_primitive_bad9( vec<string> $vec, dict<string, string> $dict, keyset<string> $keyset, vec<string> $varray, dict<string, string> $darray, vec_or_dict<string> $varray_or_darray, ): void { (int)$vec; (int)$dict; (int)$keyset; (int)$varray; (int)$darray; (int)$varray_or_darray; }
PHP
hhvm/hphp/hack/test/lint/implicit_pess/cast_non_primitive_good.php
//// a.php newtype SomeNewtype = int; //// b.php <?hh function cast_non_primitive_good1(): void { (string) 7; } function cast_non_primitive_good2(?string $bar): void { (int) $bar; } function cast_non_primitive_good3(bool $test): void { if ($test) { $x = 'test'; } else { $x = false; } (string) $x; } enum E : int { A = 42; } function cast_non_primitive_good4(E $e): void { (string) $e; (int) E::A; } function cast_non_primitive_good5(): void { (string) idx(dict[], 'banana'); } function cast_non_primitive_good6(SomeNewtype $x): void { (string) $x; } function cast_non_primitive_good7(mixed $test): void { (string) $test; } function cast_non_primitive_good8(mixed $test): void { (string) idx($test as KeyedContainer<_, _>, 'banana'); } function cast_non_primitive_good9( bool $test1, bool $test2, bool $test3, ): void { if ($test1) { $a = 'a'; } else { $a = false; } if ($test2) { $b = 12; } else { $b = 12.4; } if ($test3) { $c = $a; } else { $c = $b; } (int)$c; } function cast_non_primitive_good10_helper(): dict<string, mixed> { return dict[]; } function cast_non_primitive_good10(): ?string { return (string) idx(cast_non_primitive_good10_helper(), 'foo'); } function cast_non_primitive_good11( HH\FormatString<Str\SprintfFormat> $x, ): void { (string) $x; } function cast_non_primitive_good12( vec<string> $vec, dict<string, string> $dict, keyset<string> $keyset, vec<string> $varray, dict<string, string> $darray, vec_or_dict<string> $varray_or_darray, ): void { (bool) $vec; (bool) $dict; (bool) $keyset; (bool) $varray; (bool) $darray; (bool) $varray_or_darray; }
PHP
hhvm/hphp/hack/test/lint/implicit_pess/cast_non_primitive_ugly.php
<?hh // This file is for the test cases of the non-primitive cast linter where there // should be a lint but doing so would lead to too much noise. It would be // desirable to eventually start producing lints for the test cases in this // file. function cast_non_primitive_ugly1<<<__Explicit>> T>(T $t): void { (int) $t; } function cast_non_primitive_ugly2(dynamic $dyn): void { (int) $dyn; } function cast_non_primitive_ugly3(mixed $m): void { (int) $m; } abstract class AC { abstract const type TRet; abstract public function make(): this::TRet; } function cast(AC $obj): void { (int) $obj->make(); }
hhvm/hphp/hack/test/lint/implicit_pess/dune
(rule (alias lint_implicit_pess) (deps %{exe:../../../src/hh_single_type_check.exe} %{project_root}/hack/test/verify.py %{project_root}/hack/test/review.sh %{project_root}/hack/test/hhi/XHPTest.hhi (glob_files %{project_root}/hack/test/lint/implicit_pess/HH_FLAGS) (glob_files %{project_root}/hack/test/lint/implicit_pess/*.php) (glob_files %{project_root}/hack/test/lint/implicit_pess/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/lint/implicit_pess --program %{exe:../../../src/hh_single_type_check.exe}))) (alias (name runtest) (deps (alias lint_implicit_pess)))
PHP
hhvm/hphp/hack/test/lint/implicit_pess/redundant_as_false_positive_on_dynamic_pass.php
<?hh function redundant_as_false_positive_on_dynamic_pass( Map<string, mixed> $map ): void { $traversable = idx($map, 'traversable') as Traversable<_>; $vector = new Vector($traversable); foreach ($vector as $element) { $element as KeyedContainer<_, _>; } }
PHP
hhvm/hphp/hack/test/lint/implicit_pess/refined_non_castable.php
<?hh function bar(): vec<int> { return vec[0]; } function foo(): void { $id = bar()[0]; $id is nonnull ? (string) $id : 'null', }
PHP
hhvm/hphp/hack/test/lint/implicit_pess/switch_bad.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test1(float $x): void { switch ($x) { case 'foo': return; } } class A {} class B {} function test2(A $x): void { switch ($x) { case new B(): return; } }
PHP
hhvm/hphp/hack/test/lint/implicit_pess/switch_case_value_dynamic_check_good.php
<?hh enum E: int { A = 42; } function foo(?E $e): void { if ($e is null) { return; } switch ($e) { case E::A: echo 'hello'; } }
PHP
hhvm/hphp/hack/test/lint/implicit_pess/switch_exhaustiveness_bad.php
<?hh <<file: __EnableUnstableFeatures('union_intersection_type_hints')>> class C {} function bad_class(C $c): void { switch ($c) { case new C(): return; } } function bad_int(int $i): void { switch ($i) { case 42: return; case 24: return; } } function bad_string(string $s): void { switch ($s) { case "hi": return; case "hello": return; } } function bad_arraykey(arraykey $s): void { switch ($s) { case "hi": return; case 42: return; } } interface I {} interface J {} function bad_intersection((I & J) $o1, (I & J) $o2): void { switch ($o1) { case $o2: return; } } function bad_union((bool | string) $s): void { switch ($s) { case true: return; } }
PHP
hhvm/hphp/hack/test/lint/implicit_pess/switch_exhaustiveness_good.php
<?hh <<file: __EnableUnstableFeatures('union_intersection_type_hints')>> function good_mixed(mixed $m): void { switch ($m) { case 1: return; } } final class C {} function good_final_class(C $c): void { switch ($c) { case new C(): return; } } function good_bool(bool $b): void { switch ($b) { case true: return; case false: return; } } function good_string(string $s): void { switch ($s) { case "hi": return; case "hello": return; default: return; } } function good_arraykey(arraykey $s): void { switch ($s) { case "hi": return; case 42: return; default: return; } } /* function good_intersection((bool & arraykey) $s): void { switch ($s) { case true: return; } } */ function good_union((bool | C) $s): void { switch ($s) { case true: return; } }
PHP
hhvm/hphp/hack/test/lint/implicit_pess/switch_exhaustiveness_good2.php
<?hh enum E : string as string { A = "A"; B = "B"; } class C { public static function getE(): E { return E::A; } } function test(vec<int> $_):int { $e = C::getE(); switch ($e) { case E::A : return 1; case E::B : return 2; } }
PHP
hhvm/hphp/hack/test/map_reduce/type_counter/body.php
<?hh function f(vec<int> $v): void { $i = $v[0]; // One ~int on RHS, one on LHS, one on the whole expression $v; // No like type here $i; // One ~int here }
PHP
hhvm/hphp/hack/test/map_reduce/type_counter/class_const_receiver.php
<?hh class C { public static function m(): void {} } function f(): classname<C> { return C::class; } function like_classname_c(): void { $c = f(); $c::m(); } function classname_c(): void { $c = C::class; $c::m(); }
PHP
hhvm/hphp/hack/test/map_reduce/type_counter/class_decl.php
<?hh class C { public vec<int> $v = vec[]; public int $i = 42; public dict<string,int> $d = dict[]; public function m1(): vec<int> { return vec[]; } public function m2(): int { return 42; } public function m3(): dict<string,int> { return dict[]; } }
PHP
hhvm/hphp/hack/test/map_reduce/type_counter/class_get_receiver.php
<?hh class C { public static int $i = 42; } function f(): classname<C> { return C::class; } function like_classname_c(): void { $c = f(); $c::$i; } function classname_c(): void { $c = C::class; $c::$i; }
PHP
hhvm/hphp/hack/test/map_reduce/type_counter/function_decl2.php
<?hh // The following should have a like type in its parameter as it is effectively // returning a `vec<int>` which would get pessimised. function f(inout vec<int> $_): void {}
PHP
hhvm/hphp/hack/test/map_reduce/type_counter/obj_get_receiver.php
<?hh class C { public function m(): void {} } function f<T>(T $t): T { return $t; } function like_c(): void { $c = f<C>(new C()); $c->m(); } function c(): void { $c = new C(); $c->m(); }
PHP
hhvm/hphp/hack/test/nast/canonical_happly_hint.php
<?hh function canon_int(int $x): void {} function canon_bool(bool $x): void {} function canon_float(float $x): void {} function canon_string(string $x): void {} function canon_darray(darray<arraykey,int> $x): void {} function canon_varray(varray<arraykey> $x): void {} function canon_varray_or_darray1(varray_or_darray<arraykey> $x): void {} function canon_varray_or_darray2(varray_or_darray<arraykey,int> $x): void {} function canon_vec_or_dict(vec_or_dict<arraykey> $x): void {} function canon_vec_or_dict1(vec_or_dict<arraykey,int> $x): void {} function canon_null(null $x): void {} function canon_num(num $x): void {} function canon_resource(resource $x): void {} function canon_arraykey(arraykey $x): void {} function canon_mixed(mixed $x): void {} function canon_nonnull(nonnull $x): void {} function canon_dynamic(dynamic $x): void {} function canon_nothing(nothing $x): void {} function canon_classname(classname $x): void {} class C { public function canon_this(this $x): void {} } class D<T> { public function canon_class_typaram(T $x): void {} } function canon_function_typaram<T>(T $x): void {}
PHP
hhvm/hphp/hack/test/nast/case_aliased_primitive.php
<?hh function disallowed_case_aliases( Int $_, Bool $_, Float $_, String $_, DArray $_, VArray $_, Varray_or_darray $_, Vec_or_dict $_, This $_, ): void {} function allowed_case_aliases( Null $_, Void $_, Num $_, Resource $_, Arraykey $_, Mixed $_, Nonnull $_, Nothing $_, ): void {}
PHP
hhvm/hphp/hack/test/nast/cconst.hhi.php
//// cconst.hhi <?hh class Klass { const int X1 = 0; const int X2; const string Y; const FunctionCredential Z; const int BAD = 'hello'; }
PHP
hhvm/hphp/hack/test/nast/coeffects_poly_var.php
<?hh function poly<Texplicit as D>( C $change, // Type hint replaced with T$change ?C $nchange, // Type hint replaced with ?T$nchange Texplicit $remain, ?Texplicit $nremain, )[$change::Co1, $nchange::Co2, $remain::Co3, $nremain::Co4]: void {}
hhvm/hphp/hack/test/nast/dune
(rule (alias nast) (deps %{exe:../../src/hh_single_type_check.exe} %{project_root}/hack/test/verify.py %{project_root}/hack/test/review.sh (glob_files %{project_root}/hack/test/nast/class_level_where_clauses/HH_FLAGS) (glob_files %{project_root}/hack/test/nast/class_level_where_clauses/*.php) (glob_files %{project_root}/hack/test/nast/class_level_where_clauses/*.exp) (glob_files %{project_root}/hack/test/nast/coeffects/HH_FLAGS) (glob_files %{project_root}/hack/test/nast/coeffects/*.php) (glob_files %{project_root}/hack/test/nast/coeffects/*.exp) (glob_files %{project_root}/hack/test/nast/everything_sdt/HH_FLAGS) (glob_files %{project_root}/hack/test/nast/everything_sdt/*.php) (glob_files %{project_root}/hack/test/nast/everything_sdt/*.exp) (glob_files %{project_root}/hack/test/nast/function_pointers/HH_FLAGS) (glob_files %{project_root}/hack/test/nast/function_pointers/*.php) (glob_files %{project_root}/hack/test/nast/function_pointers/*.exp) (glob_files %{project_root}/hack/test/nast/interpret_soft_types_as_like_types/HH_FLAGS) (glob_files %{project_root}/hack/test/nast/interpret_soft_types_as_like_types/*.php) (glob_files %{project_root}/hack/test/nast/interpret_soft_types_as_like_types/*.exp) (glob_files %{project_root}/hack/test/nast/like_type_hints/HH_FLAGS) (glob_files %{project_root}/hack/test/nast/like_type_hints/*.php) (glob_files %{project_root}/hack/test/nast/like_type_hints/*.exp) (glob_files %{project_root}/hack/test/nast/supportdyn_type_hints/HH_FLAGS) (glob_files %{project_root}/hack/test/nast/supportdyn_type_hints/*.php) (glob_files %{project_root}/hack/test/nast/supportdyn_type_hints/*.exp) (glob_files %{project_root}/hack/test/nast/HH_FLAGS) (glob_files %{project_root}/hack/test/nast/*.php) (glob_files %{project_root}/hack/test/nast/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/nast --program %{exe:../../src/hh_single_type_check.exe}))) (alias (name runtest) (deps (alias nast)))
PHP
hhvm/hphp/hack/test/nast/elab_shape_field_name.php
<?hh final class WithConstantName { const string FLD1 = 'field1'; public function self_inside_class(): shape(self::FLD1 => int) { return shape(self::FLD1 => 1); } } type with_class_constant = shape(WithConstantName::FLD1 => int); type with_self_outside_class = shape(self::FLD1 => int); type with_string_name = shape("field1" => int); // Note this is currently a parse error but not a naming error type with_int_name = shape(1 => int);
PHP
hhvm/hphp/hack/test/nast/expression_tree_for.php
<?hh function test(): void { ExampleDsl`() ==> { for ($i = 0; true; $i = $i + 1) { foo(); } }`; }
PHP
hhvm/hphp/hack/test/nast/expression_tree_function_order.php
<?hh function test(): void { ExampleDsl` foo( bar( baz(), qux(), ), qaal(), )`; }
PHP
hhvm/hphp/hack/test/nast/file_attributes_from_multiple_namespaces.php
<?hh // strict namespace A; <<file: AttrA>> class AttrA implements \HH\FileAttribute { } namespace B; <<file: AttrB>> class AttrB implements \HH\FileAttribute { }
PHP
hhvm/hphp/hack/test/nast/file_attributes_in_namespaces.php
<?hh // strict namespace MyNamespace; <<file: MyFileAttribute>> class MyFileAttribute implements \HH\FileAttribute { } class MyClass { } new module my.module {}
PHP
hhvm/hphp/hack/test/nast/file_attributes_in_namespaces_with_namespaced_values.php
<?hh // strict namespace A { class MyStringFileAttribute implements \HH\FileAttribute { public function __construct(public string $attr_value) { } } class MyClass { const string MY_CLASS_CONST = 'my class const value' } <<file: MyStringFileAttribute(MyClass::MY_CLASS_CONST)>> } namespace B { class MyOtherClass { } }
PHP
hhvm/hphp/hack/test/nast/fun_decl.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 $v): void;
PHP
hhvm/hphp/hack/test/nast/fun_empty.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 $v): void {}
PHP
hhvm/hphp/hack/test/nast/gconst.hhi.php
//// gconst.hhi <?hh const int X1 = 0; const int X2; const string Y; const FunctionCredential Z; const int BAD = 'hello';
PHP
hhvm/hphp/hack/test/nast/hh_show.php
<?hh <<file:__EnableUnstableFeatures('expression_trees')>> function test(): void { ExampleDsl`() ==> { $x = 1; hh_show($x); }`; }
PHP
hhvm/hphp/hack/test/nast/invalid_enum_class.php
<?hh function invalid_enum_class_1(\HH\BuiltinEnum<int> $x): void {} function invalid_enum_class_2(\HH\BuiltinEnumClass<int> $x): void {} function invalid_enum_class_3(\HH\BuiltinAbstractEnumClass $x): void {}
PHP
hhvm/hphp/hack/test/nast/invalid_xhp.php
<?hh function invalid_xhp_1(Xhp::T $x): void {} function invalid_xhp_2(:Xhp::T $x): void {} function invalid_xhp_3(XHP::T $x): void {}
PHP
hhvm/hphp/hack/test/nast/like_hint_is_expr.php
<?hh class C {} function like_hint_is_expr(mixed $x): bool { if($x is ~C) { return true; } return false; }
PHP
hhvm/hphp/hack/test/nast/like_hint_upcast_expr.php
<<file:__EnableUnstableFeatures('upcast_expression')>> <?hh class A {} function like_hint_upcast_expr(mixed $x): void { $_ = $x upcast ~A; }
PHP
hhvm/hphp/hack/test/nast/naming_error.php
<?hh class MyClass { // Printing the NAST should not crash if we have a naming // error. Instead, we should just print it. const int X = baz(); } function baz(): void {}
PHP
hhvm/hphp/hack/test/nast/nonreturn_habstr_hkt.php
<?hh class ABC<T1<T2>> { public function nonreturn_habstr_void_hkt(T1<void> $x): void {} public function nonreturn_habstr_noreturn_hkt(T1<noreturn> $x): void {} }
PHP
hhvm/hphp/hack/test/nast/nonreturn_happly.php
<?hh function nonreturn_happly_void(Awaitable<void> $x): void {} function nonreturn_happly_void(Awaitable<noreturn> $x): void {}
PHP
hhvm/hphp/hack/test/nast/nonreturn_toplevel.php
<?hh function nonreturn_toplevel_void(void $x): int { return 1; } function nonreturn_toplevel_noreturn(noreturn $x): int { return 1; }
PHP
hhvm/hphp/hack/test/nast/numeric_literals_underscores.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class BigNumbersRUs { const float fp = 1_2_3.4_5_6; const float fpexp = 1_2_3e-4_5_6; const float fpdot = .1_2_3e-4_5_6; const float fpleading = 0.1_2_3_4e+2_5; const float fpleadingexp = 0e-1_5; const float fpoct = 03_41.51_36; const int dec = 1_234_567_890; const int hex = 0xff_cc_123_4; const int bin = 0b11_00_11_00; const int oct = 0666_555_444; const int neg_dec = -1_234_567_890; const int neg_hex = -0xff_cc_123_4; const int neg_bin = -0b11_00_11_00; const int neg_oct = -0666_555_444; }
PHP
hhvm/hphp/hack/test/nast/pipe_exprs.php
<?hh function takes_an_int(int $int): void {} function pipe_param_call(int $x): void { $x |> takes_an_int($$); } function pipe_local_call(): void { $x = 1; $x |> takes_an_int($$); } class Foo { public static int $myInt = 0; } function pipe_taccess(): void { $foo = Foo::class; $foo |> $$::$myInt; } function pipe_taccess_call(): void { $foo |> takes_an_int($$::$myInt); }
PHP
hhvm/hphp/hack/test/nast/placeholders.php
<?hh function placeholder_param(int $_): void {} function returns_int() : int { return 0; } function placeholder_local(): void { $_ = returns_int(); } function placeholder_foreach_val(vec<int> $xs): void { foreach($xs as $_) {} } function placeholder_foreach_keyval_val(dict<string,int> $xs): void { foreach($xs as $k => $_) {} } function placeholder_foreach_keyval_key(dict<string,int> $xs): void { foreach($xs as $_ => $v) {} } function placeholder_foreach_keyval(dict<string,int> $xs): void { foreach($xs as $_ => $_) {} }
PHP
hhvm/hphp/hack/test/nast/scope_resolution.php
<?hh // keep in sync with hphp/hack/test/tast/scope_resolution.php function bar(): string { return 'class'; } final class Foo { const string bar = 'baz'; const vec<nothing> class = vec[]; public static (function(): int) $_ = self::class<>; public static function bar(): float { return 3.14159; } public static function class(): int { return 42; } } // keep in sync with hphp/hack/test/tast/scope_resolution.php function class_const(dynamic $x): void { Foo::bar; $x::bar; Foo::bar(); $x::bar(); (Foo::bar); (($x::bar)); (((Foo::bar)))(); (((($x::bar))))(); Foo::bar\baz; (Foo::bar\baz); Foo::bar\baz(); (Foo::bar\baz)(); Foo::{bar}; (Foo::{bar}); Foo::{bar}(); (Foo::{bar})(); Foo::{(bar)}; (Foo::{((bar))}); Foo::{(((bar)))}(); (Foo::{((((bar))))})(); Foo::{bar\baz}; (Foo::{bar\baz}); Foo::{bar\baz}(); (Foo::{bar\baz})(); Foo::class; (Foo::class); Foo::class(); (Foo::class)(); Foo::{''}; (Foo::{''}); Foo::{''}(); (Foo::{''})(); Foo::{"bar"}; (Foo::{'bar'}); Foo::{'bar'}(); (Foo::{"bar"})(); Foo::{"bar\\baz"}; (Foo::{'bar\\baz'}); Foo::{'bar\\baz'}(); (Foo::{"bar\\baz"})(); Foo::{'class'}; (Foo::{"class"}); Foo::{"class"}(); (Foo::{'class'})(); Foo::{'$x'}; (Foo::{'$x'}); Foo::{'$x'}(); (Foo::{'$x'})(); Foo::{"\$x"}; (Foo::{"\$x"}); Foo::{"\$x"}(); (Foo::{"\$x"})(); Foo::{'$_'}; (Foo::{'$_'}); Foo::{'$_'}(); (Foo::{'$_'})(); Foo::{"\$_"}; (Foo::{"\$_"}); Foo::{"\$_"}(); (Foo::{"\$_"})(); Foo::{<<<EOD such amaze$ $ EOD }; (Foo::{<<<'EOD' very $wow EOD })(); } // keep in sync with hphp/hack/test/tast/scope_resolution.php function class_get(dynamic $x): void { Foo::$x; $x::$x; Foo::$x(); $x::$x(); (Foo::$x); (($x::$x)); (((Foo::$x)))(); (((($x::$x))))(); Foo::$_; (Foo::$_); Foo::$_(); (Foo::$_)(); Foo::{$x}; (Foo::{$x}); Foo::{$x}(); (Foo::{$x})(); Foo::{$_}; (Foo::{$_}); Foo::{$_}(); (Foo::{$_})(); Foo::{bar()}(); Foo::{vsprintf('%s', 'wow')}(); Foo::{(string)(123 + 456)}(); Foo::{'ba'."r"}(); Foo::{"bar\\".'baz'}(); Foo::{"$x"}(); Foo::{"$_"}(); Foo::{"ba$x"}(); Foo::{"ba$_"}(); Foo::{$x()}(); Foo::{$_()}(); Foo::{<<<EOD $much doge EOD }(); } function invalid_exprs(dynamic $x): void { // Foo::'bar'; // (Foo::"bar"); // Foo::"bar"(); // (Foo::'bar')(); Foo::{bar()}; (Foo::{bar().baz()}); (Foo::{vsprintf('%s', 'wow')})(); Foo::{'ba'."r"}; (Foo::{'ba'."r"}); (Foo::{"b".'ar'})(); Foo::{"$x"}; (Foo::{"$x"}); (Foo::{"$x"})(); Foo::{"$_"}; (Foo::{"$_"}); (Foo::{"$_"})(); Foo::{"ba$x"}; (Foo::{"ba$x"}); (Foo::{"ba$x"})(); Foo::{"ba$_"}; (Foo::{"ba$_"}); (Foo::{"ba$_"})(); Foo::{$x()}; (Foo::{$x()}); (Foo::{$x()})(); Foo::{$_()}; (Foo::{$_()}); (Foo::{$_()})(); }
PHP
hhvm/hphp/hack/test/nast/stmt_match.php
<?hh function f(mixed $v): void { match ($v) { $i: int => echo "int $i\n"; _: string => echo "string $v\n"; _ => echo "unknown\n"; $x => echo "unreachable\n"; } }
PHP
hhvm/hphp/hack/test/nast/stmt_match_block.php
<?hh function f(mixed $v): void { match ($v) { $i: int => { echo "int $i\n"; } _: string => { echo "string $v\n"; } _ => { echo "unknown\n"; } $x => { echo "unreachable\n"; } } }
PHP
hhvm/hphp/hack/test/nast/taccess_context.php
<?hh class WithConstant { const ctx C = [io]; public function uses_self_C()[self::C]: void {} } abstract class AnotherClassWithConstant { abstract const ctx C; abstract public function uses_this_C()[this::C]: void; abstract public function uses_another_C()[WithConstant::C]: void; }
PHP
hhvm/hphp/hack/test/nast/taccess_parent.php
<?hh class DEF { const type T = int; } class ABC extends DEF { public function taccess_parent(parent::T $x): void {} }
PHP
hhvm/hphp/hack/test/nast/taccess_tparam.php
<?hh abstract class C { abstract const type TA; } function taccess_tparam<T>(T $x, T::TA $y): void where T1 as C {}
PHP
hhvm/hphp/hack/test/nast/taccess_tparam_context.php
<?hh abstract class WithConstant { abstract const ctx C; } class C<reify T as WithConstant> { public function taccess_tparam_context()[T::C]: void {} }
PHP
hhvm/hphp/hack/test/nast/taccess_tparam_where_clause.php
<?hh abstract class C { abstract const type TA; } function taccess_tparam_where_clause<T1, T2>(T1 $x, T2 $y): void where T1 as C, T2 as T1::TA {}
PHP
hhvm/hphp/hack/test/nast/this_class_tparam_bound.php
<?hh class C<T as this> { private ?T $x; } abstract class C<T as this::X> { abstract const type X; }
PHP
hhvm/hphp/hack/test/nast/this_hint_extends_generic.php
<?hh class B<T> {} class C extends B<this> {} // Ok, not generic final class D extends B<this> {} // Not ok, subtyping possible by variance final class E<+T> extends B<this> {} // Not ok, subtyping possible by variance final class F<-T> extends B<this> {} // Ok, invariant final class G<T> extends B<this> { public ?T $x }
PHP
hhvm/hphp/hack/test/nast/this_hint_require_extends_indirect.php
<?hh class C<T> {} trait Foo<T> { require extends C<T>; } class A extends C<int> { use Foo<this>; }
PHP
hhvm/hphp/hack/test/nast/this_this_extends_type_access.php
<?hh interface I1 {} interface I2 extends I1 {} abstract class A1<T as I2> {} abstract class A2 extends A1<this::TI> { const type TI = I1; }
PHP
hhvm/hphp/hack/test/nast/top_level.php
<?hh namespace { use namespace HH\Lib\{C, Math, Vec}; func_foo(); use function My\Full\func_foo; foo(); 1+foo(); $x = Vec\range(1, 99); func_foo(); function func_foo() {} function foo() {} } namespace My\Full { function func_foo() {} } namespace HH\Lib\Vec { function range($_, $_) {} }
PHP
hhvm/hphp/hack/test/nast/tycon_arity_prim.php
<?hh function tycon_arity_bool(bool<bool> $x): void {} function tycon_arity_int(int<int> $x) : void {} function tycon_arity_float(float<float> $x): void {} function tycon_arity_num(num<num> $x): void {} function tycon_arity_string(string<string> $x): void {} function tycon_arity_arraykey(arraykey<arraykey> $x): void {} function tycon_arity_resource(resource<resource> $x): void {} function tycon_arity_mixed(mixed<mixed> $x): void {} function tycon_arity_nonnull(nonnull<mixed> $x): void {} function tycon_arity_nothing(nothing<mixed> $x): void {} function tycon_arity_void(): void<mixed> {}
PHP
hhvm/hphp/hack/test/nast/tycon_arity_user_defined.php
<?hh class StayClassy<Ta,Tb> { private ?Ta; private ?Tb; } function tycon_arity_user_defined0(StayClassy $x): void {} function tycon_arity_user_defined1(StayClassy<int> $x): void {} function tycon_arity_user_defined2(StayClassy<int,bool> $x): void {} function tycon_arity_user_defined3(StayClassy<int,bool,string> $x): void {}
PHP
hhvm/hphp/hack/test/nast/wildcard_call_expr.php
<?hh function my_id<T>(T $x): T { return $x; } function wildcard_call(): void { my_id<_>(42); }
PHP
hhvm/hphp/hack/test/nast/wildcard_collection_lit_expr.php
<?hh function wildcard_varray(): void { $x = varray<_>[]; } function wildcard_vec(): void { $x = vec<_>[]; } function wildcard_keyset(): void { $x = keyset<_>[]; } function wildcard_darray(): void { $x = darray<_, _>[]; } function wildcard_dict(): void { $x = dict<_, _>[]; }
PHP
hhvm/hphp/hack/test/nast/wildcard_fn_ptr.php
<?hh function my_id<T>(T $x): T { return $x; } function wildcard_fn_ptr(): void { $x = my_id<_>; }
PHP
hhvm/hphp/hack/test/nast/wildcard_hint_as_expr.php
<?hh class AAAAA {} final class BBBBB<+T> extends AAAAA { private ?T $x; } function wildcard_hint_is_expr(AAAAA $x): void { $_ = $x as BBBBB<_>; }
PHP
hhvm/hphp/hack/test/nast/wildcard_hint_is_expr.php
<?hh class AAAAA {} final class BBBBB<+T> extends AAAAA { private ?T $x; } function wildcard_hint_is_expr(AAAAA $x): bool { if ($x is BBBBB<_>) { return true; } return false; }
PHP
hhvm/hphp/hack/test/nast/wildcard_hint_shape.php
<?hh function wilcard_hint_shape_toplevel(mixed $x): void { $x as shape('y' => _); $x as shape('y' => int, 'z' => _); $x as shape('y' => _, 'z' => string); $x as shape('y' => _, 'z' => _); $x as shape('y' => shape('z' => _)); $x as shape('y' => _, 'w' => shape('z' => _)); } function wildcard_hint_shape_nested(mixed $x): void { $x is shape('x' => vec<_>); $x is shape('x' => shape('y' => vec<_>)); $x is shape('x' => dict<_, _>); $x is shape('x' => int, 'y' => dict<_, _>); $x is shape('x' => shape('y' => dict<_, _>)); $x as shape('x' => vec<_>); $x as shape('x' => shape('y' => vec<_>)); $x as shape('x' => dict<_, _>); $x as shape('x' => int, 'y' => dict<_, _>); $x as shape('x' => shape('y' => dict<_, _>)); }
PHP
hhvm/hphp/hack/test/nast/wildcard_hint_upcast_expr_invalid.php
<<file:__EnableUnstableFeatures('upcast_expression')>> <?hh class A {} class B<T> {} function wildcard_hint_upcast_expr(A $x): void { $_ = $x upcast B<_>; }
PHP
hhvm/hphp/hack/test/nast/wildcard_new_expr.php
<?hh function wildcard_vector(Traversable<int> $xs): void { $_ = new Vector<_>($xs); } function wildcard_map(KeyedTraversable<int, bool> $xs): void { $_ = new Map<_, _>($xs); }
PHP
hhvm/hphp/hack/test/nast/case_types/case_types_basic.php
<?hh <<file:__EnableUnstableFeatures('case_types')>> case type CT1<+T1 as arraykey, -T2, T> as nonnull = keyset<T1> | (function(T2): T); case type CT2 as arraykey, num = int; case type CT3 = string | bool;
PHP
hhvm/hphp/hack/test/nast/case_types/case_types_in_module.php
<?hh <<file:__EnableUnstableFeatures('case_types')>> module some.mod; internal case type CT1 = int; public case type CT2 = int; <<SomeAttr>> case type CT3 = int;
PHP
hhvm/hphp/hack/test/nast/class_level_where_clauses/test_class_level_where_clauses.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 SingleConstr <T> where T = int {} class ListConstrs <T> where T = int T = string {} class MultiConstrs <T, Tu> where T = int, Tu = string Tu = int {} class AsConstr <T> where T as int {} class SuperConstr <T> where T super int {}
PHP
hhvm/hphp/hack/test/nast/coeffects/anon.php
<?hh function anons_with_ctx_list(): void { $anon_no_use = function()[output]: int use () { return 0; }; $x = 1; $anon_no_ret = function()[non_det] use ($ret) { return $x; }; $anon = function()[rx]: int use ($ret) { return $x; }; }
PHP
hhvm/hphp/hack/test/nast/coeffects/ctx_alias.php
<?hh <<file:__EnableUnstableFeatures('context_alias_declaration')>> newctx X as [] = [defaults]; function test()[\X]: void {}
PHP
hhvm/hphp/hack/test/nast/coeffects/ctx_const2.php
<?hh <<file: __EnableUnstableFeatures('union_intersection_types')>> class CWithConst { const ctx C = [io, rand]; const type C1 = (\HH\Capabilities\IO & \HH\Capabilities\Rand); }
PHP
hhvm/hphp/hack/test/nast/coeffects/ctx_const_abstract.php
<?hh abstract class CWithConst { abstract const ctx C1; // bare abstract abstract const ctx C2 = [io]; // abstract with default abstract const ctx C3 as [io, rand]; // abstract with bound abstract const ctx C4 super [io, rand] as [io] = [io]; // abstract with multiple bounds and default }
PHP
hhvm/hphp/hack/test/nast/coeffects/ctx_const_both_bounds.php
<?hh interface WithLowerThenUpperBound { abstract const ctx C super [defaults] as [rx]; } interface WithUpperThenLowerBound { abstract const ctx C as [write_props] super [defaults]; }
PHP
hhvm/hphp/hack/test/nast/coeffects/ctx_const_lower_bound.php
<?hh abstract class C { abstract const ctx C super [defaults]; } class D { const ctx C super [defaults] = []; }
PHP
hhvm/hphp/hack/test/nast/coeffects/ctx_const_naespacing.php
<?hh <<file:__EnableUnstableFeatures('context_alias_declaration_short')>> newctx X as [write_props]; abstract class A { const ctx C = [read_globals, X]; abstract const ctx C2 as [read_globals, X] = [read_globals, X]; }
PHP
hhvm/hphp/hack/test/nast/coeffects/ctx_const_upper_bound.php
<?hh abstract class C { abstract const ctx C as [write_props]; } class D { const ctx C as [write_props] = [defaults]; }
PHP
hhvm/hphp/hack/test/nast/coeffects/poly_ctx.php
<?hh function poly( (function (int)[_]: void) $f, ?(function (string)[_]: bool) $nf, )[ctx $f, ctx $nf]: void {}
PHP
hhvm/hphp/hack/test/nast/everything_sdt/enum_class_base.php
<?hh enum class PessEnumClassSupportDynBound : mixed { int ONE = 1; string TWO = 'two'; } enum class PessEnumClass : arraykey { int ONE = 1; string TWO = 'two'; } interface IHasName { public function name(): string; } abstract enum class PessAbstracEnumClas: IHasName { abstract HasName Foo; HasName Bar = new HasName('bar'); } enum PessRegularEnum : string { Yes = 'Y'; No = 'N'; } enum PessRegularEnumBound : arraykey as arraykey { Yes = 'Y'; No = 42; }
PHP
hhvm/hphp/hack/test/nast/everything_sdt/tparam_upper_bound.php
<?hh class C {} function tparam_upper_bound_where<T>(): void where T as C {} function tparam_upper_bound<T as C>(): void {}
PHP
hhvm/hphp/hack/test/nast/expression_tree_virtualize_functions/expression_tree_for.php
<?hh function test(): void { ExampleDsl`() ==> { for ($i = 0; true; $i = $i + 1) { foo(); } }`; }
PHP
hhvm/hphp/hack/test/nast/expression_tree_virtualize_functions/expression_tree_function_order.php
<?hh function test(): void { ExampleDsl` foo( bar( baz(), qux(), ), qaal(), )`; }
PHP
hhvm/hphp/hack/test/nast/expression_tree_virtualize_functions/hh_show.php
<?hh <<file:__EnableUnstableFeatures('expression_trees')>> function test(): void { ExampleDsl`() ==> { $x = 1; hh_show($x); }`; }
PHP
hhvm/hphp/hack/test/nast/function_pointers/class_meth.php
<?hh namespace Foo\Bar; final class Fizz { public static function buzz(): void {} } function baz(): void { // Elaborate the class $x = Fizz::buzz<>; // Vector is autoimported class $x = Vector::fromItems<>; }
PHP
hhvm/hphp/hack/test/nast/function_pointers/function_pointer.php
<?hh namespace Foo\Bar; function qux(): void {} function baz(): void { // Expect this name to be elaborated qux<>; // is_vec is autoimported function $x = is_vec<>; // vec is autoimported function $x = vec<>; }
PHP
hhvm/hphp/hack/test/nast/interpret_soft_types_as_like_types/tcopt_soft_as_like_enabled.php
<<file:__EnableExperimentalFeatures('interpret_soft_types_as_like_types')>> <?hh function tcopt_soft_as_like_enabled(<<__Soft>> int $x): @int { return $x + 1; }
PHP
hhvm/hphp/hack/test/nast/like_type_hints/tcopt_like_types_enabled.php
<<file:__EnableExperimentalFeatures('like_type_hints')>> <?hh function tcopt_like_types_enabled(~int $x): void {}
PHP
hhvm/hphp/hack/test/nast/typeconsts/multiple-bounds_as-only.php
<?hh abstract class A { abstract const type T0; abstract const type T1 as string; abstract const type T2 as arraykey as int; abstract const type T3 as int as arraykey as num = int; }
PHP
hhvm/hphp/hack/test/nast/typeconsts/multiple-bounds_mixed-kind.php
<?hh abstract class A { abstract const type T1 as arraykey super int; abstract const type T2 super A as nonnull; abstract const type T2 super string as nonnull as mixed super nothing; }
PHP
hhvm/hphp/hack/test/nast/typeconsts/multiple-bounds_super-only.php
<?hh abstract class A { abstract const type T0; abstract const type T1 super string; abstract const type T2 super arraykey super int; abstract const type T3 super int super arraykey = arraykey; }