language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
PHP
hhvm/hphp/hack/test/hover/readonly_keyword_return.php
<?hh class Foo { public function __construct(public int $prop) {} } function bar(): readonly Foo { // ^ hover-at-caret throw new Exception(); }
PHP
hhvm/hphp/hack/test/hover/readonly_method_call.php
<?hh class Foo { // This is a property. public (function(): void) $foo; public function __construct() { $this->foo = () ==> {}; } // This is a method. public readonly function foo(): void {} public readonly function callReadonlyMethod(): void { $this->foo(); // ^ hover-at-caret } }
PHP
hhvm/hphp/hack/test/hover/recompose-like-fun.php
<?hh enum E : int as arraykey { A = 0; } class B { public function f(int $x) : arraykey { return "s"; } } class C extends B { public function f(int $x) : E { return E::A; } } function f() : void { $c = new C(); $y = $x ==> $c->f($x); // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/recompose-like.php
<?hh enum E : int as arraykey { A = 0; } class B { public function f(int $x) : arraykey { return "s"; } } class C extends B { public function f(int $x) : E { return E::A; } } function f() : void { $c = new C(); $x = $c->f(1); // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/sdt_function_dynamic.php
<?hh <<__SupportDynamicType>> function first(vec<int> $vi):int { return $vi[0]; // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/sdt_function_lambda.php
<?hh // (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. <<__SupportDynamicType>> function first(vec<int> $vi):int { $x = 5; $g = () ==> { return $x; // ^ hover-at-caret }; return $g(); }
PHP
hhvm/hphp/hack/test/hover/sdt_function_onetype.php
<?hh <<__SupportDynamicType>> function first(bool $b, vec<int> $vi): vec<int> { if ($b) { return $vi; } else $x = vec[3]; return $x; // ^ hover-at-caret } }
PHP
hhvm/hphp/hack/test/hover/sdt_method_dynamic.php
<?hh <<__SupportDynamicType>> class Box<T> { public function __construct(private ~T $x) {} public function set(T $y) : void { $this->x = $y; // ^ hover-at-caret } public function get() : ~T {return $this->x;} }
PHP
hhvm/hphp/hack/test/hover/static_property_access.php
<?hh class Foo { public static int $x = 1; public function demo(): void { $this::$x; // ^ hover-at-caret } }
PHP
hhvm/hphp/hack/test/hover/type-const_multiple-as_0.php
<?hh interface I { abstract const type T1 as int as float; // intentional gibberish public function use_num(I::T1 $_): void {} // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/type-const_multiple-as_1.php
<?hh interface I extends IBase1, IBase2 { abstract const type TFstWins as int as arraykey; public function use_num(I::TFstWins $_): void {} // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/type-const_multiple-as_2.php
<?hh interface I extends IBase1, IBase2 { abstract const type TSndWins as int as arraykey; public function use_num(I::TSndWins $_): void {} // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/type-const_multiple-as_3.php
<?hh interface IBase1 {} interface IBase2 {} interface I extends IBase1, IBase2 { abstract const type TBoth as IBase1 as IBase2; public function use_num(I::TBoth $_): void {} // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/type-const_multiple-as_doc-1.php
<?hh /** Doc for IBase1 */ interface IBase1 {} interface IBase2 {} interface I extends IBase1, IBase2 { abstract const type TBoth as IBase1 as IBase2; // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/type-const_multiple-as_doc-2.php
<?hh interface IBase1 {} /** Doc for IBase2 */ interface IBase2 {} interface I extends IBase1, IBase2 { abstract const type TBoth as IBase1 as IBase2; // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/type-const_single-as.php
<?hh interface I { abstract const type T1 as num; public function use_num(I::T1 $_): void {} // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/type_alias.php
<?hh /** * Some docs. */ type myfoo = int; function return_it(): myfoo { // ^ hover-at-caret throw new Exception(); }
PHP
hhvm/hphp/hack/test/hover/type_param_class.php
<?hh class MyFoo<Tfoo> { public function bar<Tx>(): Tfoo { // ^ hover-at-caret throw new Exception(''); } }
PHP
hhvm/hphp/hack/test/hover/type_param_constraint.php
<?hh function foo<Tfoo as int>(): Tfoo { // ^ hover-at-caret throw new Exception(''); }
PHP
hhvm/hphp/hack/test/hover/type_param_method.php
<?hh class MyFoo { public function bar<Tfoo>(): Tfoo { // ^ hover-at-caret throw new Exception(''); } }
PHP
hhvm/hphp/hack/test/hover/unsafe_cast.php
<?hh function takes_string(string $_): void {} function call_it(int $i): void { takes_string(HH\FIXME\UNSAFE_CAST<int,string>($i, 'lying to hh is bad')); // ^ hover-at-caret }
hhvm/hphp/hack/test/hover/unsafe_cast.php.imp_pess_exp
Parameter: $_ ------------- ~string `UNSAFE_CAST` allows you to lie to the type checker. **This is almost always a bad idea**. You might get an exception, or you might get an unexpected value. Even scarier, you might cause an exception in a totally different part of the codebase. ``` UNSAFE_CAST<Dog, Cat>($my_dog, 'my reason here')->meow() ``` In this example, the type checker will accept the code, but the code will still crash when you run it (no such method "meow" on "Dog"). `UNSAFE_CAST` has no runtime effect. It only affects the type checker. The above example will run the same as `$my_dog->meow()`. ## You can fix it! It is always possible to write code without `UNSAFE_CAST` and without `HH_FIXME`. This usually requires changing type signatures and some refactoring. Your code will be more reliable, the type checker can help you, and future changes will be less scary. `UNSAFE_CAST` is still better than `HH_FIXME`, because `HH_FIXME` applies to the entire next line, and `UNSAFE_CAST` applies to a single expression.
PHP
hhvm/hphp/hack/test/hover/use_var.php
<?hh function myfoo(int $x): void { $_ = function() use ($x) {}; // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/xhp_literal_attribute.php
<?hh final class :foo:bar { attribute /** * docs for name */ string name; } function main(): void { <foo:bar name=""/>; // ^ hover-at-caret }
PHP
hhvm/hphp/hack/test/hover/xhp_literal_class.php
<?hh /** * docs for :foo:bar */ final class :foo:bar { attribute string name; } function main(): void { <foo:bar name=""/>; // ^ hover-at-caret }
hhvm/hphp/hack/test/ident/dune
(executable (name test_early) (link_flags (:standard (:include ../../src/dune_config/ld-opts.sexp))) (modes exe byte_complete) (modules test_early) (libraries heap_ident heap_libc test_injector_config)) (rule (alias early) (deps test_early.exe) (action (run ./test_early.exe))) (executable (name test_handoff) (link_flags (:standard (:include ../../src/dune_config/ld-opts.sexp))) (modes exe byte_complete) (modules test_handoff) (libraries heap_ident heap_shared_mem test_injector_config)) (rule (alias handoff) (deps test_handoff.exe) (action (run ./test_handoff.exe))) (executable (name test_workers) (link_flags (:standard (:include ../../src/dune_config/ld-opts.sexp))) (modes exe byte_complete) (modules test_workers) (libraries core_kernel heap_ident heap_shared_mem procs_entry_point test_injector_config)) (rule (alias workers) (deps test_workers.exe) (action (ignore-stdout (run ./test_workers.exe)))) (alias (name runtest) (deps (alias early) (alias handoff) (alias workers)))
OCaml
hhvm/hphp/hack/test/ident/test_early.ml
(* Assert that the early counter starts at 1 and grows monotonically *) let rec loop prev = function | 0 -> () | n -> let i = Ident.tmp () in assert (prev < i); loop i (n - 1) let () = let one = Ident.tmp () in assert (one == 1); loop one 10_000
OCaml
hhvm/hphp/hack/test/ident/test_handoff.ml
(* Assert that the early counter hands off to the concurrent counter without overlap *) let rec loop prev = function | 0 -> () | n -> let i = Ident.tmp () in assert (prev < i); loop i (n - 1) let () = let early = Ident.tmp () in (* Initializing shared mem will switch over to the concurrent counter, even * if we never connect any workers. *) let handle = SharedMem.init ~num_workers:0 { SharedMem.global_size = 0; heap_size = 0; hash_table_pow = 0; shm_dirs = []; shm_use_sharded_hashtbl = false; shm_cache_size = -1; shm_min_avail = 0; log_level = 0; sample_rate = 0.0; compression = 0; } in ignore (handle : SharedMem.handle); loop early 10_000; ()
OCaml
hhvm/hphp/hack/test/ident/test_workers.ml
module Hh_bucket = Bucket (* Bucket is shadowed by Core/Core_kernel *) open Hh_prelude module IntKey = struct type t = int let to_string = string_of_int let compare = Int.compare end module Ids = SharedMem.Heap (SharedMem.ImmediateBackend (SharedMem.NonEvictable)) (IntKey) (struct type t = int array let description = "Test_Ids" end) let entry = WorkerControllerEntryPoint.register ~restore:(fun () ~(worker_id : int) -> Hh_logger.set_id (Printf.sprintf "test_workers %d" worker_id)) let () = Daemon.check_entry_point (); let num_workers = 4 in let handle = SharedMem.init ~num_workers { SharedMem.global_size = 0; heap_size = 10 * 1024 * 1024; (* 10 MiB *) hash_table_pow = 14; (* 256 KiB *) shm_dirs = []; shm_use_sharded_hashtbl = false; shm_cache_size = -1; shm_min_avail = 0; log_level = 0; sample_rate = 0.0; compression = 0; } in let workers = MultiWorker.make ?call_wrapper:None ~longlived_workers:false ~saved_state:() ~entry num_workers ~gc_control:(Gc.get ()) ~heap_handle:handle in let num_jobs = 100 in let ids_per_job = 100 in (* Ensure all ids within a job increase monotonically. *) let job () job_id = let ids = Array.create ~len:ids_per_job 0 in let prev = ref 0 in for i = 0 to ids_per_job - 1 do let id = Ident.tmp () in ids.(i) <- id; assert (!prev < id); prev := id done; Printf.printf "Adding job %d\n" job_id; Ids.add job_id ids; () in (* Also add some ids from the master process *) let () = job () 0 in let job_id = ref 1 in let next () = let i = !job_id in if i < num_jobs then ( incr job_id; Hh_bucket.Job i ) else Hh_bucket.Done in let merge () () = () in MultiWorker.call (Some workers) ~neutral:() ~job ~merge ~next; (* Ensure ids are globally unique. *) let all_ids_len = num_jobs * ids_per_job in let all_ids = Array.create ~len:all_ids_len 0 in for job_id = 0 to num_jobs - 1 do (* Might raise because of Option.value_exn *) let ids = Option.value_exn (Ids.get job_id) in for i = 0 to ids_per_job - 1 do all_ids.((job_id * ids_per_job) + i) <- ids.(i) done done; Array.sort ~compare:( - ) all_ids; let prev = ref 0 in for i = 0 to all_ids_len - 1 do let id = all_ids.(i) in assert (!prev < id); prev := id done; ()
PHP
hhvm/hphp/hack/test/identify_symbol/catch.php
<?hh function might_throw(): void {} class Foo extends Exception {} function test() { try { might_throw(); } catch (Foo $foo) { } }
PHP
hhvm/hphp/hack/test/identify_symbol/classname.php
<?hh // strict class C { public static function foo(): void {} } function test(): void { $cls = C::class; $cls::foo(); }
PHP
hhvm/hphp/hack/test/identify_symbol/constructor_inheritance.php
<?hh class C { public function __construct() {} } class Foo extends C {} function test() { new Foo(); }
hhvm/hphp/hack/test/identify_symbol/dune
(rule (alias identify_symbol) (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/identify_symbol/HH_FLAGS) (glob_files %{project_root}/hack/test/identify_symbol/*.flags) (glob_files %{project_root}/hack/test/identify_symbol/*.php) (glob_files %{project_root}/hack/test/identify_symbol/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/identify_symbol --program %{exe:../../src/hh_single_type_check.exe}))) (alias (name runtest) (deps (alias identify_symbol)))
PHP
hhvm/hphp/hack/test/identify_symbol/fake_member.php
<?hh class C { private ?int $foo = null; public function get(): void { if ($this->foo) { $this->foo; } } }
PHP
hhvm/hphp/hack/test/identify_symbol/function_parameter.php
<?hh // strict class C { public function __construct(string $s) {} } function test(): void { $string = "aaaaaaaa"; new C($string); }
PHP
hhvm/hphp/hack/test/identify_symbol/generic.php
<?hh // TODO(t11082787): identifying generics class C<TFoo> { public function test(): TFoo { //UNSAFE } }
PHP
hhvm/hphp/hack/test/identify_symbol/intersection.php
<?hh class C1 { public function foo() {} } class C2 { public function foo() {} } function test(C1 $c1, C2 $c2, bool $b) { if ($b) { $x = $c1; } else { $x = $c2; } $x->foo(); }
PHP
hhvm/hphp/hack/test/identify_symbol/method.php
<?hh class Foo { public function bar() { // blah blah multiline method } } function test(Foo $foo) { $foo->bar(); }
PHP
hhvm/hphp/hack/test/identify_symbol/method_inheritance.php
<?hh class C { public function foo() {} } class D extends C {} function test(D $d) { $d->foo(); }
PHP
hhvm/hphp/hack/test/identify_symbol/namespace_use.php
<?hh //strict // TODO(t11082787): identify namespace use statements namespace N1 { function test() : void{ } } use N1\test;
PHP
hhvm/hphp/hack/test/identify_symbol/typeconst_access.php
<?hh class C { const type BAR = string; } class D { const type FOO = C; } function test(): D::FOO::BAR { return ""; }
PHP
hhvm/hphp/hack/test/identify_symbol/typedef2.php
<?hh // strict class SomeClass {} type SomeTypeAlias = SomeClass; function test( SomeClass $c, SomeTypeAlias $d ) : void {}
PHP
hhvm/hphp/hack/test/identify_symbol/undefined_symbol.php
<?hh // strict function test() { // we know the type, position and name of this symbol, but we won't know // where it's definition is undefined_function(); }
PHP
hhvm/hphp/hack/test/identify_symbol/xhp_property.php
<?hh class C { attribute string xhp_string = "aaa" @required; public function test() { $this->:xhp_string; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/add_local_type_hint/add_local_type_hint_1.php
<?hh <<file:__EnableUnstableFeatures('typed_local_variables')>> function f() : void { // convert to `let $the_variable: int = 1;` /*range-start*/$the_variable/*range-end*/ = 1; }
PHP
hhvm/hphp/hack/test/ide_code_actions/add_local_type_hint/add_local_type_hint_10.php
<?hh <<file:__EnableUnstableFeatures('typed_local_variables')>> function f(int $x) : void { $x = () ==> { // add a type hint for `$y` /*range-start*/$y = 3;/*range-end*/ }(); }
PHP
hhvm/hphp/hack/test/ide_code_actions/add_local_type_hint/add_local_type_hint_2.php
<?hh <<file:__EnableUnstableFeatures('typed_local_variables')>> function f() : void { // convert to `let $the_variable: int = 1;` /*range-start*/$the_variable = 1;/*range-end*/ }
PHP
hhvm/hphp/hack/test/ide_code_actions/add_local_type_hint/add_local_type_hint_3.php
<?hh <<file:__EnableUnstableFeatures('typed_local_variables')>> function f() : void { // should offer no refactoring /*range-start*/let list($x, $y) = tuple(1, 2);/*range-end*/ }
PHP
hhvm/hphp/hack/test/ide_code_actions/add_local_type_hint/add_local_type_hint_4.php
<?hh <<file:__EnableUnstableFeatures('typed_local_variables')>> function f() : void { // Do not offer the refactoring: hints are not valid here foreach(vec[1, 2] as /*range-start*/$the_variable/*range-end*/) { $the_variable = 1; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/add_local_type_hint/add_local_type_hint_5.php
<?hh <<file:__EnableUnstableFeatures('typed_local_variables')>> function f() : void { $the_variable = 3; // don't offer the refactoring: not enough information to indicate the user intends to refactor `$x` $x = /*range-start*/$the_variable/*range-end*/; }
PHP
hhvm/hphp/hack/test/ide_code_actions/add_local_type_hint/add_local_type_hint_6.php
<?hh <<file:__EnableUnstableFeatures('typed_local_variables')>> function f() : void { $the_variable = 1; // do not offer the refactoring for compound assingments /*range-start*/$the_variable/*range-end*/ += 2; }
PHP
hhvm/hphp/hack/test/ide_code_actions/add_local_type_hint/add_local_type_hint_7.php
<?hh function f() : void { // No refactoring should be offered as 'local_type_variables' is not enabled for this file. /*range-start*/$the_variable/*range-end*/ = 1; }
PHP
hhvm/hphp/hack/test/ide_code_actions/add_local_type_hint/add_local_type_hint_8.php
<?hh <<file:__EnableUnstableFeatures('typed_local_variables')>> function f(int $x) : void { // don't offer the refactoring: no indication that the user intends to refactor `$the_variable` $the_variable = 1 + /*range-start*/$x/*range-end*/; }
PHP
hhvm/hphp/hack/test/ide_code_actions/add_local_type_hint/add_local_type_hint_9.php
<?hh <<file:__EnableUnstableFeatures('typed_local_variables')>> function f(int $x) : void { // don't offer the refactoring when multiple statements are selected /*range-start*/ $x = 0; $y = 0; /*range-end*/ }
hhvm/hphp/hack/test/ide_code_actions/add_local_type_hint/dune
(rule (alias ide_code_actions_add_local_type_hint) (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/ide_code_actions/add_local_type_hint/HH_FLAGS) (glob_files %{project_root}/hack/test/ide_code_actions/add_local_type_hint/*.php) (glob_files %{project_root}/hack/test/ide_code_actions/add_local_type_hint/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ide_code_actions/add_local_type_hint --program %{exe:../../../src/hh_single_type_check.exe} --flags --ide-code-actions "Add local type hint"))) (alias (name runtest) (deps (alias ide_code_actions_add_local_type_hint)))
hhvm/hphp/hack/test/ide_code_actions/add_override/dune
(rule (alias ide_code_actions_add_override) (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/ide_code_actions/add_override/HH_FLAGS) (glob_files %{project_root}/hack/test/ide_code_actions/add_override/*.php) (glob_files %{project_root}/hack/test/ide_code_actions/add_override/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ide_code_actions/add_override --program %{exe:../../../src/hh_single_type_check.exe} --flags --ide-code-actions "Add override"))) (alias (name runtest) (deps (alias ide_code_actions_add_override)))
PHP
hhvm/hphp/hack/test/ide_code_actions/add_override/method_override_1.php
<?hh class TheParent { public function foo(): void {} } class B extends /*range-start*/TheParent/*range-end*/ {}
hhvm/hphp/hack/test/ide_code_actions/extract_classish/dune
(rule (alias ide_code_actions_extract_classish) (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/ide_code_actions/extract_classish/HH_FLAGS) (glob_files %{project_root}/hack/test/ide_code_actions/extract_classish/*.php) (glob_files %{project_root}/hack/test/ide_code_actions/extract_classish/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ide_code_actions/extract_classish --program %{exe:../../../src/hh_single_type_check.exe} --flags --ide-code-actions "Extract "))) (alias (name runtest) (deps (alias ide_code_actions_extract_classish)))
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_classish/extract_classish_abstract_1.php
<?hh // We don't provide "Extract interface" refactors for abstract classes. // Probably nothing wrong with providing it, though, just needs more // logic to handle abstract methods. abstract class A { /*range-start*/ public abstract function foo(): void; public function bar(): void { echo 1 + 1; } /*range-end*/ }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_classish/extract_classish_basic_1.php
<?hh class A { /*range-start*/ public function foo(): void { 400 + 8; } public int $x; private function bar(): void {} public function baz(): int { return 400 + 8; } /*range-end*/ }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_classish/extract_classish_comments_1.php
<?hh class A { // Ensure that we don't comment out the closing brace in extracted interface methods /*range-start*/ public function foo(): void { // comment on first line } /*range-end*/ }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_classish/extract_classish_extends_1.php
<?hh class TheParent {} class A extends TheParent { /*range-start*/ public function foo(): void { 400 + 8; } public function bar(): void { 400 + 8; } /*range-end*/ }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_classish/extract_classish_extract_classish_async.php
<?hh class A { /*range-start*/ public async function foo(): Awaitable<void> {} /*range-end*/ }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_classish/extract_classish_implements_1.php
<?hh class TheParent {} interface I {} class A extends TheParent implements I { /*range-start*/ public function foo(): void { 400 + 8; } /*range-end*/ }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_classish/extract_classish_implements_2.php
<?hh class TheParent {} interface I {} interface J {} class A extends TheParent implements I, J { /*range-start*/ public function foo(): void { 400 + 8; } /*range-end*/ }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_classish/extract_classish_use_1.php
<?hh trait Tr {} class A { use Tr; /*range-start*/ public function foo(): void { 400 + 8; } public int $x; /*range-end*/ }
hhvm/hphp/hack/test/ide_code_actions/extract_method/dune
(rule (alias ide_code_actions_extract_method) (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/ide_code_actions/extract_method/HH_FLAGS) (glob_files %{project_root}/hack/test/ide_code_actions/extract_method/*.php) (glob_files %{project_root}/hack/test/ide_code_actions/extract_method/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ide_code_actions/extract_method --program %{exe:../../../src/hh_single_type_check.exe} --flags --ide-code-actions "Extract into method"))) (alias (name runtest) (deps (alias ide_code_actions_extract_method)))
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_async_1.php
<?hh async function foo(): Awaitable<void> {} class Klass { public async function foo(): Awaitable<void> { $ignore1 = 1; /*range-start*/ $local = await foo(); /*range-end*/ $ignore2 = 1; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_async_iterator_1.php
<?hh class Klass { public async function foo(int $x): AsyncIterator<int> { /*range-start*/ await gen_void(); $y = $x; yield 3; /*range-end*/ $z = $y } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_async_iterator_2.php
<?hh async function async_it(): AsyncIterator<string> { yield "key1"; yield "key2"; } class Klass { public static async function m(int $x): Awaitable<void> { $x = 0; /*range-start*/ foreach (async_it() await as $v) { $x++; } /*range-end*/ $y = $x; } } <<__EntryPoint>> function main(): void { \HH\Asio\join(Klass::m(1)); }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_async_iterator_3.php
<?hh async function gen_void(): Awaitable<void> {} async function async_keyed_it(): AsyncKeyedIterator<string, int> { yield "key1" => 1; yield "key2" => 2; } class Klass { public static async function m(int $x): Awaitable<void> { $x = 0; /*range-start*/ foreach (async_keyed_it() await as $k => $v) { $x++ } await gen_void(); /*range-end*/ $y = $x; } } <<__EntryPoint>> function main(): void { \HH\Asio\join(Klass::m(1)); }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_bad_expr_range_1.php
<?hh class Klass { public function foo(): void { $x = /*range-start*/1 * 2/*range-end*/ + 3; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_bad_selection_1.php
<?hh class Klass { public function foo(): void { /*range-start*/$x = 1; $y = /*range-end*/3; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_bad_selection_2.php
<?hh class Klass { public function foo(): void { // bad range, so no code actions expected $x = /*range-start*/ 1 * (2/*range-end*/ + 3); } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_bad_ty.php
<?hh class Klass { public function foo(): void { $z = nonexistent(); /*range-start*/ $x = $z->meth($z);/*range-end*/ $x + 2; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_concurrent_1.php
<?hh async function gen_int(): Awaitable<int> { return 1; } class Klass { public async function foo(): Awaitable<int> { /*range-start*/ concurrent { $x = await gen_int(); $y = await gen_int(); } /*range-end*/ return $x + $y; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_cond_1.php
<?hh function cond(): bool { return false; } class Klass { public function foo(): void { if (cond()) { while (cond()) { /*range-start*/ $x = 1; $y = $x; /*range-end*/; } } } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_cond_2.php
<?hh class Klass { public function foo(): void { if (1 < 2) { // extracting a method here should not change what is printed /*range-start*/ $x = 1; /*range-end*/ } else { $x = 4; } echo $x; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_expr_1.php
<?hh class Klass { public function foo(): void { $x = /*range-start*/1 * 2/*range-end*/; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_expr_2.php
<?hh function cond(): bool { return false; } class Klass { public function foo(): void { if (cond()) { while (cond()) { $x = /*range-start*/3 + 2/*range-end*/; } } } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_generator_1.php
<?hh class Klass { public function foo(int $x): void { /*range-start*/ $y = $x; yield 1; /*range-end*/ $z = $y; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_iterator_1.php
<?hh class Klass { public function foo(): Iterator<int> { /*range-start*/ yield 2; /*range-end*/ } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_iterator_2.php
<?hh class Klass { public function foo(): KeyedIterator<int, string> { /*range-start*/ yield 2 => ""; /*range-end*/ } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_lfun_1.php
<?hh class Klass { public function foo(): void { $shadowed = true; $referenced = true; // should become a param to the extracted method /*range-start*/ (() ==> { $shadowed = false || $referenced; }); /*range-end*/ $z = $shadowed; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_lfun_2.php
<?hh function foo((function(): int) $f): void {} class A { public function main(): void { foo(() ==> // We offer a refactor even though the selection // corresponds to a `return` statement in the tast. /*range-start*/3 + 3/*range-end*/ ); } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_namespace_1.php
<?hh async function genVoid(): Awaitable<void> {} class Klass { public function foo(int $n): void { $awaitable = genVoid(); /*range-start*/ $x = $n * 2; $y = $awaitable; /*range-end*/ $x + 2; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_nonstatic.php
<?hh class Klass { public function one(): int { return 1; } public function foo(): void { // The extracted function is static iff the function we are extracting from is static. /*range-start*/ $return = $this->one(); /*range-end*/ var_dump($return); } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_params_1.php
<?hh class Foo<T> { public function __construct(public T $x) {} } class Klass { public function foo(): void { $ignore1 = 1; $param1 = 1; $param2 = ""; $param2 = new Foo($param2); /*range-start*/ $param1 = $param1; $z = $param2; /*range-end*/ $ignore2 = 1; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_params_and_returns.php
<?hh class Klass { public function foo(): void { $ignore1 = 1; $param1 = 1; $param2 = 1; $param3_and_ret1 = 1; /*range-start*/ $param3_and_ret1 = $param3_and_ret1 + $param1; $local = $param3_and_ret1 + $param2; $param3_and_ret1 = $local; $ret2 = 1; /*range-end*/ $ignore2 = 0; $ignore3 = $param3_and_ret1; $ignore3 = $ret2; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_placeholders_1.php
<?hh class Klass { public function method0(): void {} public static async function method1(): Promise<void> {} public function method2(): void { // extracted method should be called "method3" because 0-2 inclusive are taken /*range-start*/ $x = 1; /*range-end*/ } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_returns_1.php
<?hh class Klass { public function foo(): void { $ignore1 = 1; /*range-start*/ $local = 100; /*range-end*/ $ignore2 = 1; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_returns_2.php
<?hh class Klass { public function foo(): void { $ignore1 = 1; /*range-start*/ $return = 100; /*range-end*/ $ignore2 = 1 + $return; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_returns_3.php
<?hh class Foo<T> { public function __construct(public T $x) {} } class Klass { public function foo(): void { $ignore1 = 1; /*range-start*/ $return1 = 100; $local = 500 + $return1; $return2 = new Foo($local); /*range-end*/ $ignore2 = 1 + $return1; var_dump($return2); } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_return_1.php
<?hh class Klass { public function foo(): int { /*range-start*/ if (1 < 2) { return 1; } else { $x = 4; } /*range-end*/ return 4; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_static.php
<?hh class Klass { public static function foo(): void { // The extracted function is static iff the function we are extracting from is static. /*range-start*/ $return = 100; /*range-end*/ var_dump($return); } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_method/extract_method_union_1.php
<?hh class Klass { public function foo(): void { if (rand()) { $z = true; } else { $z = ""; } /*range-start*/ $x = $z;/*range-end*/ $x + 2; } }
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/dune
(rule (alias ide_code_actions_extract_shape_type) (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/ide_code_actions/extract_shape_type/HH_FLAGS) (glob_files %{project_root}/hack/test/ide_code_actions/extract_shape_type/*.php) (glob_files %{project_root}/hack/test/ide_code_actions/extract_shape_type/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ide_code_actions/extract_shape_type --program %{exe:../../../src/hh_single_type_check.exe} --flags --ide-code-actions "Extract shape type"))) (alias (name runtest) (deps (alias ide_code_actions_extract_shape_type)))
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_1.php
<?hh class Other {} class A {} function foo(): void { $a = new A(); $x =/*range-start*/ shape("a" => 2, "b" => $a) /*range-end*/; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_10.php
<?hh class Other {} class A {} function foo(): void { $a = new A(); $x = /*range-start*/(() ==> shape('a' => 2, 'b' => $a)['a'])()/*range-end*/; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_11.php
<?hh class A { public function foo(int $x): void { /*range-start*/ $x = shape('x' => 1); $y = shape('y' => 1); /*range-end*/ } }