language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
PHP
hhvm/hphp/hack/test/autocomplete/heuristic_nothing_vs_mixed.php
<?hh interface Visibility {} final class CPublic implements Visibility {} final class CProtected implements Visibility {} class Field<+TShape, +TValue> {} class X {} enum class E : mixed { Field<shape('access' => CPublic), int> EPub = new Field(); Field<shape('access' => CProtected), string> EProt = new Field(); } function getProtectedField< TValue, TField as Field< shape('access' => CProtected, ...), TValue, >, >(HH\EnumClass\Label<E, TField> $label): TValue { invariant_violation('yolo'); } function main(): string { return getProtectedField(#AUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/local_before_call.php
<?hh function other(): void {} function do_stuff(): string { $foo = 1; $bar = 2; $baz = 3; $bAUTO332; other(); }
PHP
hhvm/hphp/hack/test/autocomplete/namespace_qualified.php
<?hh namespace { function some_other_function(): void { } function my_fun_function(): void { } } namespace N1 { function my_fun_function_2(): void { } } namespace N2 { function my_fun_function_3(): void { } function f(): void { \my_funAUTO332; } }
PHP
hhvm/hphp/hack/test/autocomplete/override_method_name.php
<?hh class Foo { public function unrelated(): void {} public static function veryLongButStatic(): void {} public function veryLongNameHere(): void {} public function veryLongNameToo(): void {} } class FooChild extends Foo { <<__Override>> public function vAUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/parent_colon_colon.php
<?hh class Ac1 { public function fun_instance(): void { } public static function fun_method(): void { } } class Bc1 extends Ac1 { public function test() { parent::fun_AUTO332 } }
PHP
hhvm/hphp/hack/test/autocomplete/parent_construct.php
<?hh class MyParent { public function __construct() {} } class MyChild extends MyParent { public function __construct() { parent::__cAUTO332 } }
PHP
hhvm/hphp/hack/test/autocomplete/regex_match.php
<?hh // strict use namespace HH\Lib\Regex; function match<T as Regex\Match>(Regex\Pattern<T> $_): T { // unsafe } function main(): void { $result = match(re"/foo(?<bar>baz)(?<herp>derp)?/"); \var_dump($result[AUTO332]); }
PHP
hhvm/hphp/hack/test/autocomplete/require_class00.php
<?hh <<file:__EnableUnstableFeatures('require_class')>> trait T { require class C; public function foo() : void { $this->bar(); } } trait T0 { reqAUTO332
PHP
hhvm/hphp/hack/test/autocomplete/shape_keys.php
<?hh type Foo = shape( 'a_abc' => string, 'a_def' => string, 'b_abc' => int, ); function foo(Foo $in): void { var_dump($in[AUTO332
PHP
hhvm/hphp/hack/test/autocomplete/shape_keys_double_quote.php
<?hh type Foo = shape( 'a_abc' => string, 'a_def' => string, 'b_abc' => int, ); function foo(Foo $in): void { var_dump($in["a_AUTO332]); }
PHP
hhvm/hphp/hack/test/autocomplete/shape_keys_ns.php
<?hh namespace MyNS; type Foo = shape( 'a_abc' => string, 'a_def' => string, 'b_abc' => int, ); function foo(Foo $in): void { var_dump($in[AUTO332
PHP
hhvm/hphp/hack/test/autocomplete/shape_keys_ns_with_prefix.php
<?hh namespace MyNS; type Foo = shape( 'a_abc' => string, 'a_def' => string, 'b_abc' => int, ); function foo(Foo $in): void { var_dump($in['a_AUTO332
PHP
hhvm/hphp/hack/test/autocomplete/shape_keys_with_prefix.php
<?hh type Foo = shape( 'a_abc' => string, 'a_def' => string, 'b_abc' => int, ); function foo(Foo $in): void { var_dump($in['a_AUTO332
PHP
hhvm/hphp/hack/test/autocomplete/shape_keys_with_prefix_not_eof.php
<?hh type Foo = shape( 'a_abc' => string, 'a_def' => string, 'b_abc' => int, ); function foo(Foo $in): void { var_dump($in['a_AUTO332]); }
PHP
hhvm/hphp/hack/test/autocomplete/shape_literal_fun_arg.php
<?hh function takes_shape(shape('foo' => int, 'foobar' => float) $_): void {} function demo(): void { takes_shape(shape('AUTO332')); }
PHP
hhvm/hphp/hack/test/autocomplete/shape_literal_fun_arg_prefix.php
<?hh function takes_shape(shape('foo' => int, 'foobar' => float, 'goo' => string, ...) $_): void {} function demo(): void { takes_shape(shape('fAUTO332')); }
PHP
hhvm/hphp/hack/test/autocomplete/shape_literal_fun_arg_unquoted.php
<?hh function takes_shape(shape('foo' => int, 'foobar' => float) $_): void {} function demo(): void { takes_shape(shape(AUTO332)); }
PHP
hhvm/hphp/hack/test/autocomplete/static_get.php
<?hh class Foo { const X = 1; static int $x = 2; public static function f() { Foo::AUTO332 // autocomplete output has no defined order } }
PHP
hhvm/hphp/hack/test/autocomplete/typeconst_bug.php
<?hh /** * Regression test: running autocomplete on a file with erroneous typeconst * used to crash the typechecker. */ class C { public function test(): C::Z { $this->AUTO332 } }
PHP
hhvm/hphp/hack/test/autocomplete/type_constant_chained_abstract.php
<?hh class X { const type TFoo = int; } abstract class Y { abstract const type TBar as X; } class Z { public function foo(): Y::TBar::TAUTO332 { } }
PHP
hhvm/hphp/hack/test/autocomplete/type_constant_chained_concrete.php
<?hh class X { const type TFoo = int; } class Y { const type TBar = X; } class Z { public function foo(): Y::TBar::TAUTO332 { } }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute.php
<?hh final class :foo:bar { attribute string name, string color; public function genRender() {} } function main(): void { <foo:bar AUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_bool.php
<?hh class :foo:bar { attribute bool my-attribute; } function main(): void { <foo:bar my-attribute={AUTO332} }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_closed.php
<?hh final class :foo:bar { attribute string name, string color, string style, int number @required; public function genRender() {} } function main(): void { <foo:bar name={'Serenity'} color={'Gray'} AUTO332/>; }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_enum_class.php
<?hh enum MyEnum: string as string { TYPE_A = "A value"; TYPE_B = "B value"; TYPE_C = "C value"; } class :foo:bar { attribute MyEnum my-attribute; } function main(): void { <foo:bar my-attribute={AUTO332} }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_enum_inline.php
<?hh class :foo:bar { attribute enum {"firefly", 1} my-attribute; } function main(): void { <foo:bar my-attribute={AUTO332} }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_enum_inline_ancestors.php
<?hh class :foo:bar { attribute enum {"firefly", 1} my-attribute; } class :banana:phone extends :foo:bar { } class :poo:bear extends :banana:phone { } function main(): void { <poo:bear my-attribute={AUTO332} }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_enum_inline_deps.php
<?hh class :foo:bar { attribute enum {"firefly", 1} my-attribute; } class :banana:phone { attribute :foo:bar; } class :poo:bear { attribute :banana:phone; } function main(): void { <poo:bear my-attribute={AUTO332} }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_no_dupes.php
<?hh final class :foo:bar { attribute string name, string color, string style, int number @required; public function genRender() {} } function main(): void { <foo:bar name={'Serenity'} color={'Gray'} AUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_no_dupes_partial.php
<?hh final class :foo:bar { attribute string name, string number, string nomenclature; public function genRender() {} } function main(): void { <foo:bar name={'Serenity'} nAUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_partial.php
<?hh class :foo:bar { attribute ?MyEnum my-attribute; } function main(): void { <foo:bar my-attrAUTO332={} }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_required.php
<?hh class :foo:bar { attribute string my-required-attribute @required; attribute string my-attribute; } function main(): void { <foAUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_required_without_snippet.php
<?hh class :foo:bar { attribute string my-required-attribute @required; attribute string my-attribute; } function main(): void { <foAUTO332 my-attribute="hello" />; }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_required_with_empty_child.php
<?hh class :foo:bar { attribute string my-required-attribute @required; attribute string my-attribute; children empty; } function main(): void { <foAUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_attribute_required_with_explicit_children.php
<?hh class :foo:bar { attribute string my-required-attribute @required; attribute string another-required-attribute @required; attribute string my-attribute; children (:p); } function main(): void { <foAUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/xhp_get.php
<?hh final class :foo:bar { attribute string name, string color; public function genRender() {} } function main(): void { $x = <foo:bar name=""/>; $x->AUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/enum_class_label/after_enum_call_call.php
<?hh enum class MyEnum: mixed { bool a_bool = true; } function get_bool(HH\EnumClass\Label<MyEnum, bool> $label): void {} class Foo { public static function bar(): void {} } function call_it(): void { get_bool(#a_bool); Foo::AUTO332 }
hhvm/hphp/hack/test/autocomplete/enum_class_label/dune
(rule (alias autocomplete_enum_class_label) (deps %{exe:../../../src/hh_single_complete.exe} %{project_root}/hack/test/verify.py %{project_root}/hack/test/review.sh (glob_files %{project_root}/hack/test/autocomplete/enum_class_label/HH_FLAGS) (glob_files %{project_root}/hack/test/autocomplete/enum_class_label/*.php) (glob_files %{project_root}/hack/test/autocomplete/enum_class_label/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/autocomplete/enum_class_label --program %{exe:../../../src/hh_single_complete.exe}))) (alias (name runtest) (deps (alias autocomplete_enum_class_label)))
PHP
hhvm/hphp/hack/test/autocomplete/enum_class_label/enum_class_label_in_call.php
<?hh class MyBox<T> { public function __construct(public T $value)[] {} } enum class MyEnum: mixed { MyBox<bool> a_bool = new MyBox(true); MyBox<int> not_bool = new MyBox(123); MyBox<bool> other_bool = new MyBox(false); } class Foo { const type TParams = MyEnum; private function getBool( HH\EnumClass\Label<this::TParams, MyBox<bool>> $label, ): void {} protected function genRun(): void { $this->getBool(#AUTO332 } }
PHP
hhvm/hphp/hack/test/autocomplete/enum_class_label/enum_class_label_method_call1.php
<?hh enum class E : mixed { int A = 42; } class C { public function f<T>(HH\EnumClass\Label<E, T> $label) : T { return E::valueOf($label); } } <<__EntryPoint>> function main(): void { $c = new C(); $c->f(E#AUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/enum_class_label/enum_class_label_method_call2.php
<?hh enum class E : mixed { int A = 42; } class C { public function f<T>(HH\EnumClass\Label<E, T> $label) : T { return E::valueOf($label); } } <<__EntryPoint>> function main(): void { $c = new C(); $c->f(#AUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/enum_class_label/enum_class_label_smethod_call1.php
<?hh enum class E : mixed { int A = 42; } class C { static public function g<T>(HH\EnumClass\Label<E, T> $label) : T { return E::valueOf($label); } } <<__EntryPoint>> function main(): void { C::g(E#AUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/enum_class_label/enum_class_label_smethod_call2.php
<?hh enum class E : mixed { int A = 42; } class C { static public function g<T>(HH\EnumClass\Label<E, T> $label) : T { return E::valueOf($label); } } <<__EntryPoint>> function main(): void { C::g(#AUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/enum_class_label/inside_method_call1.php
<?hh enum class YOLO : mixed { int POUET = 42; } function f(HH\EnumClass\Label<YOLO, int> $label, int $x) : void {} function main(): void { f(YOLO#AUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/enum_class_label/inside_method_call2.php
<?hh enum class YOLO : mixed { int POUET = 42; } function f(HH\EnumClass\Label<YOLO, int> $label, int $x) : void {} function main(): void { f(#AUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/no_builtins/dict_keys.php
<?hh function foo(): string { } function bar(dict<string, string> $in): string { return $in[AUTO332]; // This should not invoke autocomplete }
PHP
hhvm/hphp/hack/test/autocomplete/no_builtins/method_or_property_public_static.php
<?hh class Foo { // This could the beginning of a method: // public static function foo(): void {} // or a property: // public static int $x = 1; public static AUTO332 }
PHP
hhvm/hphp/hack/test/autocomplete/no_builtins/multifile.php
//// file1.php <?hh function t_alpha(): void { t_AUTO332 //// file2.php <?hh function t_beta(): void { t_bAUTO332
PHP
hhvm/hphp/hack/test/autocomplete/no_builtins_manually_invoked/dict_keys.php
<?hh function foo(): string { } function bar(dict<string, string> $in): string { return $in[AUTO332]; }
hhvm/hphp/hack/test/count_imprecise_types/dune
(rule (alias count_imprecise_types) (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/count_imprecise_types/*.php) (glob_files %{project_root}/hack/test/count_imprecise_types/*.php.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/count_imprecise_types --program %{exe:../../src/hh_single_type_check.exe} --in-extension .php --flags --count-imprecise-types --error-format plain))) (alias (name runtest) (deps (alias count_imprecise_types)))
PHP
hhvm/hphp/hack/test/count_imprecise_types/test1.php
<?hh function f(mixed $m, dynamic $d): void { $m; $d; $m; $d; if ($m is nonnull) { $m; } }
PHP
hhvm/hphp/hack/test/count_imprecise_types/test2.php
<?hh class C { public function f(mixed $m, dynamic $d): void { $m; $d; $m; $d; if ($m is nonnull) { $m; } } }
PHP
hhvm/hphp/hack/test/count_imprecise_types/test3.php
<?hh function f(mixed $m): void { $m; } function g(mixed $m): void { $m; } class C { public function f(mixed $m): void { $m; } public function g(mixed $m): void { $m; } }
JSON
hhvm/hphp/hack/test/cst_search/and_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "classish_declaration", "children": { "classish_name": { "pattern_type": "and_pattern", "patterns": [ { "pattern_type": "raw_text_pattern", "raw_text": "Foo" }, { "pattern_type": "match_pattern", "match_name": "foo class name token" }, { "pattern_type": "match_pattern", "match_name": "foo class name token 2" } ] } } } }
JSON
hhvm/hphp/hack/test/cst_search/and_no_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "classish_declaration", "children": { "classish_name": { "pattern_type": "and_pattern", "patterns": [ { "pattern_type": "raw_text_pattern", "raw_text": "Bar" }, { "pattern_type": "match_pattern", "match_name": "bar class name token" } ] } } } }
JSON
hhvm/hphp/hack/test/cst_search/basic_class.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "methodish_declaration", "children": { "methodish_function_decl_header": { "pattern_type": "node_pattern", "kind": "function_declaration_header", "children": { "function_name": { "pattern_type": "match_pattern", "match_name": "function name" } } } } } }
JSON
hhvm/hphp/hack/test/cst_search/basic_class_no_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "methodish_declaration", "children": { "methodish_semicolon": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "methodish_declaration", "children": {} } } } } }
hhvm/hphp/hack/test/cst_search/dune
(rule (alias cst_search) (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/cst_search/*.php) (glob_files %{project_root}/hack/test/cst_search/*.json) (glob_files %{project_root}/hack/test/cst_search/*.json.exp) (glob_files %{project_root}/hack/test/cst_search/*.flags)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/cst_search --program %{exe:../../src/hh_single_type_check.exe} --in-extension .json --stdin))) (alias (name runtest) (deps (alias cst_search)))
JSON
hhvm/hphp/hack/test/cst_search/error_in_children.json
{ "pattern_type": "node_pattern", "kind": "methodish_declaration", "children": { "methodish_function_decl_header": { "pattern_type": "node_pattern", "kind": "foo", "children": {} } } }
JSON
hhvm/hphp/hack/test/cst_search/error_non_existent_child_type.json
{ "pattern_type": "node_pattern", "kind": "methodish_declaration", "children": { "foo": { "pattern_type": "match_pattern" } } }
PHP
hhvm/hphp/hack/test/cst_search/if_with_else.php
<?hh // strict function foo(): void { if (true) { echo 'true'; } else { echo 'false'; } }
JSON
hhvm/hphp/hack/test/cst_search/list_pattern.error.1.json
{ "pattern_type": "list_pattern", "children": { "-1": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$foo" } } } }
JSON
hhvm/hphp/hack/test/cst_search/list_pattern.error.2.json
{ "pattern_type": "list_pattern", "children": { "foo": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$foo" } } } }
JSON
hhvm/hphp/hack/test/cst_search/list_pattern_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "list_pattern", "children": { "0": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$foo" } }, "1": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$bar" } } } } }
JSON
hhvm/hphp/hack/test/cst_search/list_pattern_max_length_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "list_pattern", "max_length": 2, "children": { "0": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$foo" } }, "1": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$bar" } } } } }
JSON
hhvm/hphp/hack/test/cst_search/list_pattern_max_length_no_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "list_pattern", "max_length": 1, "children": { "0": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$foo" } }, "1": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$bar" } } } } }
JSON
hhvm/hphp/hack/test/cst_search/list_pattern_no_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "list_pattern", "children": { "0": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$foo" } }, "1": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$qux" } } } } }
JSON
hhvm/hphp/hack/test/cst_search/list_pattern_out_of_bounds.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "list_pattern", "children": { "0": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$foo" } }, "1": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "$bar" } }, "2": { "pattern_type": "match_pattern", "match_name": "dummy" } } } }
JSON
hhvm/hphp/hack/test/cst_search/missing_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "if_statement", "children": { "if_else_clause": { "pattern_type": "missing_node_pattern" } } } }
JSON
hhvm/hphp/hack/test/cst_search/missing_no_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "if_statement", "children": { "if_else_clause": { "pattern_type": "missing_node_pattern" } } } }
JSON
hhvm/hphp/hack/test/cst_search/not_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "function_declaration_header", "children": { "function_modifiers": { "pattern_type": "not_pattern", "pattern": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "final" } } } } } }
JSON
hhvm/hphp/hack/test/cst_search/not_no_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "function_declaration_header", "children": { "function_modifiers": { "pattern_type": "not_pattern", "pattern": { "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "raw_text_pattern", "raw_text": "public" } } } } } }
JSON
hhvm/hphp/hack/test/cst_search/or_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "classish_declaration", "children": { "classish_name": { "pattern_type": "or_pattern", "patterns": [ { "pattern_type": "raw_text_pattern", "raw_text": "Bar" }, { "pattern_type": "raw_text_pattern", "raw_text": "Foo" } ] } } } }
JSON
hhvm/hphp/hack/test/cst_search/or_no_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "classish_declaration", "children": { "classish_name": { "pattern_type": "or_pattern", "patterns": [ { "pattern_type": "raw_text_pattern", "raw_text": "Bar" }, { "pattern_type": "raw_text_pattern", "raw_text": "Baz" } ] } } } }
JSON
hhvm/hphp/hack/test/cst_search/raw_text_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "methodish_declaration", "children": { "methodish_function_decl_header": { "pattern_type": "node_pattern", "kind": "function_declaration_header", "children": { "function_name": { "pattern_type": "raw_text_pattern", "raw_text": "bar" } } } } } }
JSON
hhvm/hphp/hack/test/cst_search/raw_text_no_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "node_pattern", "kind": "methodish_declaration", "children": { "methodish_function_decl_header": { "pattern_type": "node_pattern", "kind": "function_declaration_header", "children": { "function_name": { "pattern_type": "raw_text_pattern", "raw_text": "foo" } } } } } }
JSON
hhvm/hphp/hack/test/cst_search/subtype_match.1.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "and_pattern", "patterns": [ { "pattern_type": "type_pattern", "subtype_of": { "kind": "class", "name": "\\Supertype", "args": [] } }, { "pattern_type": "match_pattern", "match_name": "supertype" } ] } }
JSON
hhvm/hphp/hack/test/cst_search/subtype_match.2.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "and_pattern", "patterns": [ { "pattern_type": "type_pattern", "subtype_of": { "kind": "class", "name": "\\Subtype", "args": [] } }, { "pattern_type": "match_pattern", "match_name": "subtype" } ] } }
JSON
hhvm/hphp/hack/test/cst_search/subtype_match.3.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "and_pattern", "patterns": [ { "pattern_type": "type_pattern", "subtype_of": { "kind": "mixed" } }, { "pattern_type": "match_pattern", "match_name": "mixed" } ] } }
JSON
hhvm/hphp/hack/test/cst_search/subtype_no_match.json
{ "pattern_type": "descendant_pattern", "pattern": { "pattern_type": "and_pattern", "patterns": [ { "pattern_type": "node_pattern", "kind": "variable", "children": {} }, { "pattern_type": "type_pattern", "subtype_of": { "kind": "primitive", "name": "resource" } } ] } }
PHP
hhvm/hphp/hack/test/cst_search/types.php
<?hh // strict class Supertype {} class Subtype extends Supertype {} function test(Supertype $supertype, Subtype $subtype, mixed $mixed): void { }
hhvm/hphp/hack/test/custom_error/unit/dune
(library (name custom_error_unit_test) (modules test) (libraries custom_error_types custom_error_eval errors typing_defs_core typing_error heap_libc test_injector_config) (inline_tests) (preprocess (pps ppx_assert ppx_expect ppx_inline_test)))
OCaml
hhvm/hphp/hack/test/custom_error/unit/test.ml
(* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * *) [@@@warning "-40"] module Eval = Custom_error_eval module Ty = Typing_defs_core let mk_ty ty_ = Ty.mk (Typing_reason.Rnone, ty_) (* Pattern match over a `Violated_constraint` error matching exactly the tparam name for which the constraint is violated *) let%test_unit "patt string exactly" = let open Patt_error in let open Patt_locl_ty in let name = "Tviolated" in let pod_none = Pos_or_decl.none in let snd_err = Typing_error.Secondary.Violated_constraint { is_coeffect = false; cstrs = [(pod_none, (pod_none, name))]; ty_sub = LoclType (Ty.mk (Typing_reason.Rnone, Ty.Tdynamic)); ty_sup = LoclType (Ty.mk (Typing_reason.Rnone, Ty.Tdynamic)); } in let err = Typing_error.( apply_reasons ~on_error:(Reasons_callback.unify_error_at Pos.none) snd_err) in (* Matches [Apply_reasons] error with any callback, applied to [Violated_constraint] secondary error with contrained tparam `Tviolated` *) let patt = Custom_error.Error_v1 (Apply_reasons { patt_rsns_cb = Any_reasons_callback; patt_secondary = Violated_constraint { patt_cstr = Patt_string.Exactly name; patt_ty_sub = Any; patt_ty_sup = Any; }; }) in let error_message = Custom_error.Message_v1 Error_message.{ message = [Lit "Ok"] } in let custom_err = Custom_error.{ name; patt; error_message } in let custom_config = Custom_error_config.{ valid = [custom_err]; invalid = [] } in let open Core in [%test_eq: (string, Eval.Value.t) Either.t list list] (Eval.eval custom_config ~err) [[Either.First "Ok"]] (* Pattern match over the [tysub] contained in a `Violated_constraint` error; the type match requires an exact match on the class name and for it to have exactly one type param. The type param must be a shape containing a field name "a" which can be of any type *) let%test_unit "patt tysub" = let open Patt_error in let open Patt_locl_ty in let param_name = "Tviolated" in let class_name = "Classy" in let pod_none = Pos_or_decl.none in let shp = Ty.( Tshape { s_origin = Missing_origin; s_unknown_value = mk_ty Tdynamic; s_fields = TShapeMap.of_list [ ( TSFlit_str (pod_none, "c"), { sft_optional = false; sft_ty = mk_ty Tdynamic } ); ( TSFlit_str (pod_none, "a"), { sft_optional = false; sft_ty = mk_ty Tdynamic } ); ( TSFlit_str (pod_none, "b"), { sft_optional = false; sft_ty = mk_ty Tdynamic } ); ]; }) in let ty_locl_sub = Ty.Tclass ((pod_none, "\\" ^ class_name), Ty.nonexact, [mk_ty shp]) in let snd_err = Typing_error.Secondary.Violated_constraint { is_coeffect = false; cstrs = [(pod_none, (pod_none, param_name))]; ty_sub = LoclType (Ty.mk (Typing_reason.Rnone, ty_locl_sub)); ty_sup = LoclType (Ty.mk (Typing_reason.Rnone, Ty.Tdynamic)); } in let err = Typing_error.( apply_reasons ~on_error:(Reasons_callback.unify_error_at Pos.none) snd_err) in (* Matches a class with exactly one parameter where that param has a shape type with one field named 'a' which can have any type *) let patt_ty_sub = Patt_locl_ty.Apply { patt_name = Patt_name.Name { patt_namespace = Root; patt_name = Patt_string.Exactly class_name; }; patt_params = Cons { patt_hd = Shape (Fld { patt_fld = { lbl = StrLbl "a"; optional = false; patt = As { lbl = "x"; patt = Any }; }; patt_rest = Open; }); patt_tl = Nil; }; } in (* Match the subtype in our error message *) let patt = Custom_error.Error_v1 (Apply_reasons { patt_rsns_cb = Any_reasons_callback; patt_secondary = Violated_constraint { patt_cstr = Patt_string.Exactly param_name; patt_ty_sub; patt_ty_sup = Any; }; }) in let error_message = Custom_error.Message_v1 Error_message.{ message = [Lit "Ok:"; Ty_var "x"] } in let custom_err = Custom_error.{ name = "patt tysub"; patt; error_message } in let custom_config = Custom_error_config.{ valid = [custom_err]; invalid = [] } in let open Core in [%test_eq: (string, Eval.Value.t) Either.t list list] (Eval.eval custom_config ~err) [Either.[First "Ok:"; Second (Eval.Value.Ty (mk_ty Ty.Tdynamic))]] (* Pattern match over the [tysub] contained in a `Violated_constraint` error; the type match requires an exact match on the class name and for it to have exactly one type param. The type parameter may _either_ be an arraykey (which we bind to `x`) or a shape with a field named `a` (whose type we bind to `x`) *) let%test_unit "patt tysub or pattern" = let open Patt_error in let open Patt_locl_ty in let param_name = "Tviolated" in let class_name = "Classy" in let pod_none = Pos_or_decl.none in let shp = Ty.( Tshape { s_origin = Missing_origin; s_unknown_value = mk_ty Tdynamic; s_fields = TShapeMap.of_list [ ( TSFlit_str (pod_none, "c"), { sft_optional = false; sft_ty = mk_ty Tdynamic } ); ( TSFlit_str (pod_none, "a"), { sft_optional = false; sft_ty = mk_ty Tdynamic } ); ( TSFlit_str (pod_none, "b"), { sft_optional = false; sft_ty = mk_ty Tdynamic } ); ]; }) in let ty_locl_sub = Ty.Tclass ((pod_none, "\\" ^ class_name), Ty.nonexact, [mk_ty shp]) in let snd_err = Typing_error.Secondary.Violated_constraint { is_coeffect = false; cstrs = [(pod_none, (pod_none, param_name))]; ty_sub = LoclType (Ty.mk (Typing_reason.Rnone, ty_locl_sub)); ty_sup = LoclType (Ty.mk (Typing_reason.Rnone, Ty.Tdynamic)); } in let err = Typing_error.( apply_reasons ~on_error:(Reasons_callback.unify_error_at Pos.none) snd_err) in (* Matches a class with exactly one parameter where that param has a shape type with one field named 'a' which can have any type *) let patt_ty_sub = Patt_locl_ty.Apply { patt_name = Patt_name.Name { patt_namespace = Root; patt_name = Patt_string.Exactly class_name; }; patt_params = Cons { patt_hd = Or { patt_fst = As { lbl = "x"; patt = Prim Arraykey }; patt_snd = Shape (Fld { patt_fld = { lbl = StrLbl "a"; optional = false; patt = As { lbl = "x"; patt = Any }; }; patt_rest = Open; }); }; patt_tl = Nil; }; } in (* Match the subtype in our error message *) let patt = Custom_error.Error_v1 (Apply_reasons { patt_rsns_cb = Any_reasons_callback; patt_secondary = Violated_constraint { patt_cstr = Patt_string.Exactly param_name; patt_ty_sub; patt_ty_sup = Any; }; }) in let error_message = Custom_error.Message_v1 Error_message.{ message = [Lit "Ok:"; Ty_var "x"] } in let custom_err = Custom_error.{ name = "patt tysub"; patt; error_message } in let custom_config = Custom_error_config.{ valid = [custom_err]; invalid = [] } in let open Core in [%test_eq: (string, Eval.Value.t) Either.t list list] (Eval.eval custom_config ~err) [Either.[First "Ok:"; Second (Eval.Value.Ty (mk_ty Ty.Tdynamic))]] let%test_unit "test namespace" = let pod_none = Pos_or_decl.none in let param_name = "T" in let class_name = "Classy" in let ns = ["This"; "Is"; "The"; "Namespace"] in let rendered_name = String.concat "\\" @@ ns @ [class_name] in let ty = Ty.Tclass ((pod_none, rendered_name), Ty.nonexact, []) in let patt_namespace = Core.List.fold_left ~f:(fun prefix str -> Patt_name.Slash { prefix; elt = Patt_string.Exactly str }) ~init:Patt_name.Root ns in let patt_ty_sub = Patt_locl_ty.( Apply { patt_name = Patt_name.Name { patt_namespace; patt_name = Exactly class_name }; patt_params = Nil; }) in let patt = Custom_error.Error_v1 Patt_error.( Apply_reasons { patt_rsns_cb = Any_reasons_callback; patt_secondary = Violated_constraint { patt_cstr = Patt_string.Exactly param_name; patt_ty_sub; patt_ty_sup = Any; }; }) in let snd_err = Typing_error.Secondary.Violated_constraint { is_coeffect = false; cstrs = [(pod_none, (pod_none, param_name))]; ty_sub = LoclType (Ty.mk (Typing_reason.Rnone, ty)); ty_sup = LoclType (Ty.mk (Typing_reason.Rnone, Ty.Tdynamic)); } in let err = Typing_error.( apply_reasons ~on_error:(Reasons_callback.unify_error_at Pos.none) snd_err) in let error_message = Custom_error.Message_v1 Error_message.{ message = [Lit "Ok"] } in let custom_err = Custom_error.{ name = "namespaced"; patt; error_message } in let custom_config = Custom_error_config.{ valid = [custom_err]; invalid = [] } in let open Core in [%test_eq: (string, Eval.Value.t) Either.t list list] (Eval.eval custom_config ~err) [Either.[First "Ok"]]
PHP
hhvm/hphp/hack/test/decl/accept_disposable.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class Handle implements IDisposable { public function __dispose(): void {} public function foo(): void {} } function f(<<__AcceptDisposable>> Handle $h): void { }
PHP
hhvm/hphp/hack/test/decl/array_typehints.php
<?hh function a2(): darray<int, string> { throw new Exception(); } /* HH_FIXME[2071] */ function v0(): varray { return varray[]; } function v1(): varray<int> { return varray[]; } /* HH_FIXME[2071] */ function d0(): darray { return darray[]; } function d2(): darray<int, string> { return darray[]; } /* HH_FIXME[2071] */ function vd0(): varray_or_darray { throw new Exception(); } function vd1(): varray_or_darray<int> { throw new Exception(); } function vd2(): varray_or_darray<int, string> { throw new Exception(); } function vd3(): varray_or_darray<int, string, bool> { throw new Exception(); }
PHP
hhvm/hphp/hack/test/decl/async_and_generator_functions.php
<?hh function sync_function(): void {} async function async_function(): Awaitable<string> { await HH\Asio\usleep(500000); return "test"; } function generator_function(): Generator<string, int, void> { yield "test" => 5; } function generator_function_implicit_key(): Generator<int, string, void> { yield "test"; } async function async_generator(): AsyncGenerator<int, string, void> { $value = await async_function(); yield 0 => $value; }
PHP
hhvm/hphp/hack/test/decl/autoimport_in_namespace.php
<?hh namespace { type A = Traversable<int>; type B = \Traversable<int>; namespace NS { type A = Traversable<int>; type B = \Traversable<int>; } }
PHP
hhvm/hphp/hack/test/decl/autoimport_namespaces.php
<?hh type RxException = Rx\Exception; type BackslashRxException = \Rx\Exception; type RxRxException = RxRx\Exception; type MyRx = Rx;
PHP
hhvm/hphp/hack/test/decl/auto_ns_use.php
<?hh // strict namespace { namespace HH\Lib\Dict { type MixedDict = dict<arraykey, mixed>; } function make_dict(): Dict\MixedDict { return dict[]; } function get_value(Dict\MixedDict $d, arraykey $k): mixed { return $d[$k]; } type MyDict = Dict\MixedDict; }
PHP
hhvm/hphp/hack/test/decl/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/decl/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/decl/classes.php
<?hh class MyClass { private static string $staticProperty; public string $instanceProperty; protected int $protectedProperty; <<__LateInit>> public arraykey $p; public function __construct(): void {} private function privateMethod(): void {} public function publicMethod(): void {} protected function protectedMethod(): void {} public async function async_generator( string $arg1, int $arg2, ): HH\AsyncGenerator<int, string, void> { await HH\Asio\usleep(500000); yield 0 => "test"; } } abstract class MyAbstractClass {} final class MyFinalClass {} abstract final class MyStaticClass {} class MyConstructorPropertiesClass { public function __construct( private string $private, protected string $protected, public string $public, public string $hasDefault = "has default", ) {} }
PHP
hhvm/hphp/hack/test/decl/classes_consistent_construct.php
<?hh <<__ConsistentConstruct>> class C1 {} class C2 extends C1 { // new mandatory arg is not ok public function __construct(A $a) {} } class A {}
PHP
hhvm/hphp/hack/test/decl/classes_const_attribute.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. abstract class A { <<__Const>> public abstract arraykey $p; } class B extends A { <<__Const>> public int $p = 1; }
PHP
hhvm/hphp/hack/test/decl/classes_const_keyword.php
<?hh // Copyright 2004-present Facebook. All Rights Reserved. class DictConsts { const dict<int, string> CDICT = dict[2 => "folly"]; const dict<int, dict<int, string>> CNESTED_DICT = dict[2 => dict[4 => "folly"]]; const dict<int, dict<int, float>> CNESTED_DICT_FLOAT = dict[2 => dict[4 => -4.5e10, 5 => 5.0]]; } abstract class AbstractConsts { abstract const int CABSTRACT_INT; } class VecConsts { const vec<int> CVEC = vec[1, 2, 3]; const vec<vec<int>> CNESTED_VEC = vec[vec[1], vec[2], vec[3]]; } class ArrayConsts { const darray<string, int> CDARRAY = darray["test" => 1]; const keyset<string> CKEYSET = keyset['a', 'b']; const keyset<classname> CCLASSNAME_KEYSET = keyset[]; const varray<string> CVARRAY = varray['MAP_1', 'MAP_2']; } class BinopConsts { const int CINT = 4 + 5; const float CFLOAT = 4.0 - 5.0; const string CSTRING = "test"."test"; const bool CBOOL = true || false; } class ShapeConsts { const shape('a' => int, 'b' => string, ...) CSHAPE = shape('a' => 42, 'b' => 'foo', 'c' => 3.14); } class TupleConsts { const (int, ?(string, float)) COPTION = tuple(7, null); } class ClassnameConsts { const classname<TupleConsts> CCLASSNAME = TupleConsts::class; const classname<ClassnameConsts> CCLASSNAME2 = self::class; }
PHP
hhvm/hphp/hack/test/decl/classes_inferred_constant_types.php
<?hh // strict class C { const FOO = -1; const BAR = 0; const BAZ = +1; const QUX = ('s'); public function f(): void { hh_show(C::FOO); hh_show(C::BAR); hh_show(C::BAZ); hh_show(C::QUX); } }
PHP
hhvm/hphp/hack/test/decl/classes_inheritance.php
<?hh class A { public function a(): void {} public function b(): void {} } class B extends A { public function b(): void {} public function c(): void {} } interface C { public function c(): void; } interface D extends C { public function d(): void; } class E implements C { public function c(): void {} } class F extends E implements D { public function d(): void {} }
PHP
hhvm/hphp/hack/test/decl/classes_reified_generics.php
<?hh class C<reify T> {} abstract class X { <<__Reifiable>> const type TFoo = int; const type X2 = C<this::TFoo>; }
PHP
hhvm/hphp/hack/test/decl/classes_require.php
<?hh abstract class Machine { public function openDoors(): void {} public function closeDoors(): void {} } interface Fliers { public function fly(): bool; } trait Plane { require extends Machine; require implements Fliers; public function takeOff(): bool { $this->openDoors(); $this->closeDoors(); return $this->fly(); } } interface HasEngine { public function startEngine(): void; } trait Startable { require extends Machine; require implements HasEngine; public function start(): void { $this->closeDoors(); $this->startEngine(); } } class AirBus extends Machine implements Fliers, HasEngine { use Plane; use Startable; public function fly(): bool { return true; } public function startEngine(): void {} }
PHP
hhvm/hphp/hack/test/decl/classes_typeconst.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class C { const type T = int; public function f(): this::T { return 5; } public function g(): this::T2 { return "test"; } const type T2 = string; } abstract class C2 { abstract const type TConstType as C; public abstract function instantiate(this::TConstType::T $request): this::TConstType; }