language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_12.php
<?hh class A { public function foo(int $x): void { /*range-start*/ $x = shape('x' => 1); /*range-end*/ } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_13.php
<?hh class A { public function foo(): void { $x = /*range-start*/ shape( "k001" => tuple(1, 2, 3), "k002" => tuple(1, 2, 3), "k003" => tuple(1, 2, 3), "k004" => tuple(1, 2, 3), "k005" => tuple(1, 2, 3), "k006" => tuple(1, 2, 3), "k007" => tuple(1, 2, 3), "k008" => tuple(1, 2, 3), "k009" => tuple(1, 2, 3), "k010" => tuple(1, 2, 3), "k011" => tuple(1, 2, 3), "k012" => tuple(1, 2, 3), "k013" => tuple(1, 2, 3), "k014" => tuple(1, 2, 3), "k015" => tuple(1, 2, 3), "k016" => tuple(1, 2, 3), "k017" => tuple(1, 2, 3), "k018" => tuple(1, 2, 3), "k019" => tuple(1, 2, 3), "k020" => tuple(1, 2, 3), "k021" => tuple(1, 2, 3), "k022" => tuple(1, 2, 3), "k023" => tuple(1, 2, 3), "k024" => tuple(1, 2, 3), "k025" => tuple(1, 2, 3), "k026" => tuple(1, 2, 3), "k027" => tuple(1, 2, 3), "k028" => tuple(1, 2, 3), "k029" => tuple(1, 2, 3), "k030" => tuple(1, 2, 3), "k031" => tuple(1, 2, 3), "k032" => tuple(1, 2, 3), "k033" => tuple(1, 2, 3), "k034" => tuple(1, 2, 3), "k035" => tuple(1, 2, 3), "k036" => tuple(1, 2, 3), "k037" => tuple(1, 2, 3), "k038" => tuple(1, 2, 3), "k039" => tuple(1, 2, 3), "k040" => tuple(1, 2, 3), "k041" => tuple(1, 2, 3), "k042" => tuple(1, 2, 3), "k043" => tuple(1, 2, 3), "k044" => tuple(1, 2, 3), "k045" => tuple(1, 2, 3), "k046" => tuple(1, 2, 3), "k047" => tuple(1, 2, 3), "k048" => tuple(1, 2, 3), "k049" => tuple(1, 2, 3), "k050" => tuple(1, 2, 3), "k051" => tuple(1, 2, 3), "k052" => tuple(1, 2, 3), "k053" => tuple(1, 2, 3), "k054" => tuple(1, 2, 3), "k055" => tuple(1, 2, 3), "k056" => tuple(1, 2, 3), "k057" => tuple(1, 2, 3), "k058" => tuple(1, 2, 3), "k059" => tuple(1, 2, 3), "k060" => tuple(1, 2, 3), "k061" => tuple(1, 2, 3), "k062" => tuple(1, 2, 3), "k063" => tuple(1, 2, 3), "k064" => tuple(1, 2, 3), "k065" => tuple(1, 2, 3), "k066" => tuple(1, 2, 3), "k067" => tuple(1, 2, 3), "k068" => tuple(1, 2, 3), "k069" => tuple(1, 2, 3), "k070" => tuple(1, 2, 3), "k071" => tuple(1, 2, 3), "k072" => tuple(1, 2, 3), "k073" => tuple(1, 2, 3), "k074" => tuple(1, 2, 3), "k075" => tuple(1, 2, 3), "k076" => tuple(1, 2, 3), "k077" => tuple(1, 2, 3), "k078" => tuple(1, 2, 3), "k079" => tuple(1, 2, 3), "k080" => tuple(1, 2, 3), "k081" => tuple(1, 2, 3), "k082" => tuple(1, 2, 3), "k083" => tuple(1, 2, 3), "k084" => tuple(1, 2, 3), "k085" => tuple(1, 2, 3), "k086" => tuple(1, 2, 3), "k087" => tuple(1, 2, 3), "k088" => tuple(1, 2, 3), "k089" => tuple(1, 2, 3), "k090" => tuple(1, 2, 3), "k091" => tuple(1, 2, 3), "k092" => tuple(1, 2, 3), "k093" => tuple(1, 2, 3), "k094" => tuple(1, 2, 3), "k095" => tuple(1, 2, 3), "k096" => tuple(1, 2, 3), "k097" => tuple(1, 2, 3), "k098" => tuple(1, 2, 3), "k099" => tuple(1, 2, 3), "k100" => tuple(1, 2, 3), "k101" => tuple(1, 2, 3), "k102" => tuple(1, 2, 3), "k103" => tuple(1, 2, 3), "k104" => tuple(1, 2, 3), "k105" => tuple(1, 2, 3), "k106" => tuple(1, 2, 3), "k107" => tuple(1, 2, 3), "k108" => tuple(1, 2, 3), "k109" => tuple(1, 2, 3), "k110" => tuple(1, 2, 3), "k111" => tuple(1, 2, 3), "k112" => tuple(1, 2, 3), "k113" => tuple(1, 2, 3), "k114" => tuple(1, 2, 3), "k115" => tuple(1, 2, 3), "k116" => tuple(1, 2, 3), "k117" => tuple(1, 2, 3), "k118" => tuple(1, 2, 3), "k119" => tuple(1, 2, 3), "k120" => tuple(1, 2, 3), "k121" => tuple(1, 2, 3), "k122" => tuple(1, 2, 3), "k123" => tuple(1, 2, 3), "k124" => tuple(1, 2, 3), "k125" => tuple(1, 2, 3), "k126" => tuple(1, 2, 3), "k127" => tuple(1, 2, 3), "k128" => tuple(1, 2, 3), "k129" => tuple(1, 2, 3), "k130" => tuple(1, 2, 3), "k131" => tuple(1, 2, 3), "k132" => tuple(1, 2, 3), "k133" => tuple(1, 2, 3), "k134" => tuple(1, 2, 3), "k135" => tuple(1, 2, 3), "k136" => tuple(1, 2, 3), "k137" => tuple(1, 2, 3), "k138" => tuple(1, 2, 3), "k139" => tuple(1, 2, 3), "k140" => tuple(1, 2, 3), "k141" => tuple(1, 2, 3), "k142" => tuple(1, 2, 3), "k143" => tuple(1, 2, 3), "k144" => tuple(1, 2, 3), "k145" => tuple(1, 2, 3), "k146" => tuple(1, 2, 3), "k147" => tuple(1, 2, 3), "k148" => tuple(1, 2, 3), "k149" => tuple(1, 2, 3), "k150" => tuple(1, 2, 3), "k151" => tuple(1, 2, 3), "k152" => tuple(1, 2, 3), "k153" => tuple(1, 2, 3), "k154" => tuple(1, 2, 3), "k155" => tuple(1, 2, 3), "k156" => tuple(1, 2, 3), "k157" => tuple(1, 2, 3), "k158" => tuple(1, 2, 3), "k159" => tuple(1, 2, 3), "k160" => tuple(1, 2, 3), "k161" => tuple(1, 2, 3), "k162" => tuple(1, 2, 3), "k163" => tuple(1, 2, 3), "k164" => tuple(1, 2, 3), "k165" => tuple(1, 2, 3), "k166" => tuple(1, 2, 3), "k167" => tuple(1, 2, 3), "k168" => tuple(1, 2, 3), "k169" => tuple(1, 2, 3), "k170" => tuple(1, 2, 3), "k171" => tuple(1, 2, 3), "k172" => tuple(1, 2, 3), "k173" => tuple(1, 2, 3), "k174" => tuple(1, 2, 3), "k175" => tuple(1, 2, 3), "k176" => tuple(1, 2, 3), "k177" => tuple(1, 2, 3), "k178" => tuple(1, 2, 3), "k179" => tuple(1, 2, 3), "k180" => tuple(1, 2, 3), "k181" => tuple(1, 2, 3), "k182" => tuple(1, 2, 3), "k183" => tuple(1, 2, 3), "k184" => tuple(1, 2, 3), "k185" => tuple(1, 2, 3), "k186" => tuple(1, 2, 3), "k187" => tuple(1, 2, 3), "k188" => tuple(1, 2, 3), "k189" => tuple(1, 2, 3), "k190" => tuple(1, 2, 3), "k191" => tuple(1, 2, 3), "k192" => tuple(1, 2, 3), "k193" => tuple(1, 2, 3), "k194" => tuple(1, 2, 3), "k195" => tuple(1, 2, 3), "k196" => tuple(1, 2, 3), "k197" => tuple(1, 2, 3), "k198" => tuple(1, 2, 3), "k199" => tuple(1, 2, 3), "k200" => tuple(1, 2, 3), "k201" => tuple(1, 2, 3), "k202" => tuple(1, 2, 3), "k203" => tuple(1, 2, 3), "k204" => tuple(1, 2, 3), "k205" => tuple(1, 2, 3), "k206" => tuple(1, 2, 3), "k207" => tuple(1, 2, 3), "k208" => tuple(1, 2, 3), "k209" => tuple(1, 2, 3), "k210" => tuple(1, 2, 3), "k211" => tuple(1, 2, 3), "k212" => tuple(1, 2, 3), "k213" => tuple(1, 2, 3), "k214" => tuple(1, 2, 3), "k215" => tuple(1, 2, 3), "k216" => tuple(1, 2, 3), "k217" => tuple(1, 2, 3), "k218" => tuple(1, 2, 3), "k219" => tuple(1, 2, 3), "k220" => tuple(1, 2, 3), "k221" => tuple(1, 2, 3), "k222" => tuple(1, 2, 3), "k223" => tuple(1, 2, 3), "k224" => tuple(1, 2, 3), "k225" => tuple(1, 2, 3), "k226" => tuple(1, 2, 3), "k227" => tuple(1, 2, 3), "k228" => tuple(1, 2, 3), "k229" => tuple(1, 2, 3), "k230" => tuple(1, 2, 3), "k231" => tuple(1, 2, 3), "k232" => tuple(1, 2, 3), "k233" => tuple(1, 2, 3), "k234" => tuple(1, 2, 3), "k235" => tuple(1, 2, 3), "k236" => tuple(1, 2, 3), "k237" => tuple(1, 2, 3), "k238" => tuple(1, 2, 3), "k239" => tuple(1, 2, 3), "k240" => tuple(1, 2, 3), "k241" => tuple(1, 2, 3), "k242" => tuple(1, 2, 3), "k243" => tuple(1, 2, 3), "k244" => tuple(1, 2, 3), "k245" => tuple(1, 2, 3), "k246" => tuple(1, 2, 3), "k247" => tuple(1, 2, 3), "k248" => tuple(1, 2, 3), "k249" => tuple(1, 2, 3), "k250" => tuple(1, 2, 3), "k251" => tuple(1, 2, 3), "k252" => tuple(1, 2, 3), "k253" => tuple(1, 2, 3), "k254" => tuple(1, 2, 3), "k255" => tuple(1, 2, 3), "k256" => tuple(1, 2, 3), "k257" => tuple(1, 2, 3), "k258" => tuple(1, 2, 3), "k259" => tuple(1, 2, 3), "k260" => tuple(1, 2, 3), "k261" => tuple(1, 2, 3), "k262" => tuple(1, 2, 3), "k263" => tuple(1, 2, 3), "k264" => tuple(1, 2, 3), "k265" => tuple(1, 2, 3), "k266" => tuple(1, 2, 3), "k267" => tuple(1, 2, 3), "k268" => tuple(1, 2, 3), "k269" => tuple(1, 2, 3), "k270" => tuple(1, 2, 3), "k271" => tuple(1, 2, 3), "k272" => tuple(1, 2, 3), "k273" => tuple(1, 2, 3), "k274" => tuple(1, 2, 3), "k275" => tuple(1, 2, 3), "k276" => tuple(1, 2, 3), "k277" => tuple(1, 2, 3), "k278" => tuple(1, 2, 3), "k279" => tuple(1, 2, 3), "k280" => tuple(1, 2, 3), "k281" => tuple(1, 2, 3), "k282" => tuple(1, 2, 3), "k283" => tuple(1, 2, 3), "k284" => tuple(1, 2, 3), "k285" => tuple(1, 2, 3), "k286" => tuple(1, 2, 3), "k287" => tuple(1, 2, 3), "k288" => tuple(1, 2, 3), "k289" => tuple(1, 2, 3), "k290" => tuple(1, 2, 3), "k291" => tuple(1, 2, 3), "k292" => tuple(1, 2, 3), "k293" => tuple(1, 2, 3), "k294" => tuple(1, 2, 3), "k295" => tuple(1, 2, 3), "k296" => tuple(1, 2, 3), "k297" => tuple(1, 2, 3), "k298" => tuple(1, 2, 3), "k299" => tuple(1, 2, 3), "k300" => tuple(1, 2, 3), "k301" => tuple(1, 2, 3), "k302" => tuple(1, 2, 3), "k303" => tuple(1, 2, 3), "k304" => tuple(1, 2, 3), "k305" => tuple(1, 2, 3), "k306" => tuple(1, 2, 3), "k307" => tuple(1, 2, 3), "k308" => tuple(1, 2, 3), "k309" => tuple(1, 2, 3), "k310" => tuple(1, 2, 3), "k311" => tuple(1, 2, 3), "k312" => tuple(1, 2, 3), "k313" => tuple(1, 2, 3), "k314" => tuple(1, 2, 3), "k315" => tuple(1, 2, 3), "k316" => tuple(1, 2, 3), "k317" => tuple(1, 2, 3), "k318" => tuple(1, 2, 3), "k319" => tuple(1, 2, 3), "k320" => tuple(1, 2, 3), "k321" => tuple(1, 2, 3), "k322" => tuple(1, 2, 3), "k323" => tuple(1, 2, 3), "k324" => tuple(1, 2, 3), "k325" => tuple(1, 2, 3), "k326" => tuple(1, 2, 3), "k327" => tuple(1, 2, 3), "k328" => tuple(1, 2, 3), "k329" => tuple(1, 2, 3), "k330" => tuple(1, 2, 3), "k331" => tuple(1, 2, 3), "k332" => tuple(1, 2, 3), "k333" => tuple(1, 2, 3), "k334" => tuple(1, 2, 3), "k335" => tuple(1, 2, 3), "k336" => tuple(1, 2, 3), "k337" => tuple(1, 2, 3), "k338" => tuple(1, 2, 3), "k339" => tuple(1, 2, 3), "k340" => tuple(1, 2, 3), "k341" => tuple(1, 2, 3), "k342" => tuple(1, 2, 3), "k343" => tuple(1, 2, 3), "k344" => tuple(1, 2, 3), "k345" => tuple(1, 2, 3), "k346" => tuple(1, 2, 3), "k347" => tuple(1, 2, 3), "k348" => tuple(1, 2, 3), "k349" => tuple(1, 2, 3), "k350" => tuple(1, 2, 3), "k351" => tuple(1, 2, 3), "k352" => tuple(1, 2, 3), "k353" => tuple(1, 2, 3), "k354" => tuple(1, 2, 3), "k355" => tuple(1, 2, 3), "k356" => tuple(1, 2, 3), "k357" => tuple(1, 2, 3), "k358" => tuple(1, 2, 3), "k359" => tuple(1, 2, 3), "k360" => tuple(1, 2, 3), "k361" => tuple(1, 2, 3), "k362" => tuple(1, 2, 3), "k363" => tuple(1, 2, 3), "k364" => tuple(1, 2, 3), "k365" => tuple(1, 2, 3), "k366" => tuple(1, 2, 3), "k367" => tuple(1, 2, 3), "k368" => tuple(1, 2, 3), "k369" => tuple(1, 2, 3), "k370" => tuple(1, 2, 3), "k371" => tuple(1, 2, 3), "k372" => tuple(1, 2, 3), "k373" => tuple(1, 2, 3), "k374" => tuple(1, 2, 3), "k375" => tuple(1, 2, 3), "k376" => tuple(1, 2, 3), ); /*range-end*/; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_2.php
<?hh class A {} class C { public 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_3.php
<?hh class C { public function foo(): void { $x =/*range-start*/ shape() /*range-end*/; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_4.php
<?hh class C { public function foo(): void { $a = 3; if (1 < 2) { $a = true; } $x =/*range-start*/ shape("the_union" => $a) /*range-end*/; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_5.php
<?hh class C { public function foo(): void { $x =/*range-start*/ shape("a" => C::nonexistent()) /*range-end*/; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_6.php
<?hh class C { public function foo(vec<int> $v): void { $x =/*range-start*/ shape("a" => $v[0]) /*range-end*/; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_7.php
<?hh class C { public function foo(vec<int> $v): void { $x =/*range-start*/ shape("a" => shape("b" => $v)) /*range-end*/; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_8.php
<?hh class Other {} class A {} function foo(): void { /*range-start*/ $a = new A(); $x =shape('a' => 2, 'b' => $a)/*range-end*/; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_9.php
<?hh class Other {} class A {} function foo(): void { $a = new A(); $x = /*range-start*/false || shape('a' => 2, 'b' => $a)/*range-end*/; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_like_types.php
<?hh function foo(vec<shape('a' => int)> $v): void { $sh = $v[0]; // This test may fail if we start using the tast under Sound Dynamic (https://fburl.com/code/9lkro66x). // If that happens, then try stripping "like types" (`~shape()` to `shape()`) /*range-start*/$sh/*range-end*/; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type/extract_shape_type_var_1.php
<?hh class C { public function foo(shape(?"a" => int, ...) $sh): void { $sh["b"] = 3; $x =/*range-start*/$sh/*range-end*/; } }
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type_to_alias/dune
(rule (alias ide_code_actions_extract_shape_type_to_alias) (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_to_alias/HH_FLAGS) (glob_files %{project_root}/hack/test/ide_code_actions/extract_shape_type_to_alias/*.php) (glob_files %{project_root}/hack/test/ide_code_actions/extract_shape_type_to_alias/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ide_code_actions/extract_shape_type_to_alias --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_to_alias)))
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type_to_alias/extract_shape_type_to_alias_2.php
<?hh class A { public function foo(/*range-start*/shape('a' => int, ...)/*range-end*/ $_): void {} }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type_to_alias/extract_shape_type_to_alias_3.php
<?hh type TShape = shape('a' => int); class A { // we don't provide the refactoring unless a shape hint literal is selected public function foo(/*range-start*/TShape/*range-end*/ $_): void {} }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type_to_alias/extract_shape_type_to_alias_4.php
<?hh class A { public function foo(shape('a' => /*range-start*/shape('inner' => int)/*range-end*/) $_): void {} }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_shape_type_to_alias/extract_shape_type_to_alias_5.php
<?hh function foo(): /*range-start*/shape('a' => int, ...)/*range-end*/ { return shape('a' => 1); }
hhvm/hphp/hack/test/ide_code_actions/extract_variable/dune
(rule (alias ide_code_actions_extract_variable) (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_variable/HH_FLAGS) (glob_files %{project_root}/hack/test/ide_code_actions/extract_variable/*.php) (glob_files %{project_root}/hack/test/ide_code_actions/extract_variable/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ide_code_actions/extract_variable --program %{exe:../../../src/hh_single_type_check.exe} --flags --ide-code-actions "Extract into variable"))) (alias (name runtest) (deps (alias ide_code_actions_extract_variable)))
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_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_variable/extract_variable_2.php
<?hh function main(): void { $placeholder0 = ""; // the next placeholder should be called: $placeholder1 $x = /*range-start*/1 * 2/*range-end*/ + 3; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_3.php
<?hh function main(): void { $placeholder1 = ""; // expecting `$placeholder2` defined here $x = /*range-start*/1 * 2/*range-end*/ + 3; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_4.php
<?hh <<__EntryPoint>> function main(): void { // expect variable extracted to here $z = 100 + /* */ 3 * (/*range-start*/3 * 2 * 7/*range-end*/); }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_bad_selection_1.php
<?hh class Klass { public function foo(): void { // Bad selection because the selected nodes don't have a common root. // In such cases, Kotlin and TypeScript also do not provide "extract into variable" 100 * /*range-start*/200 + 300/*range-end*/; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_class_const_1.php
<?hh class A { // we should not offer the "Extract Variable" refactor here const x = /*range-start*/2222/*range-end*/; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_class_var_1.php
<?hh class A { // we should not offer the "Extract Variable" refactor here int $x = /*range-start*/2222/*range-end*/; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_const_1.php
<?hh // we should not offer the "Extract Variable" refactor here const x = /*range-start*/2222/*range-end*/;
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_lambda_1.php
<?hh <<__EntryPoint>> function main(): void { // No variable extraction expected $z = 100 + () ==>/*range-start*/300 + 2/*range-end*/ }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_lambda_2.php
<?hh <<__EntryPoint>> function main(): void { $z = 100 + () ==>{ $x = 3; // expect variable extracted to here return /*range-start*/300 // + 2/*range-end*/; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_lambda_4.php
<?hh function map<T>(vec<T> $v, (function(T): T) $f): vec<T> { return vec[]; } function main(): void { () ==> map(vec[], $item ==> { $y = /*range-start*/$item + 1/*range-end*/; return $y; }); }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_lambda_5.php
<?hh function map<T>(vec<T> $v, (function(T): T) $f): vec<T> { return vec[]; } function main(): void { () ==> map(vec[], function($item) { $y = /*range-start*/$item + 1/*range-end*/; return $y; }); }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_lambda_6.php
<?hh function foo(): void { // The curly braces in the param complicate our expression lambda check. // Make sure we don't crash. (($a = () ==> {}) ==> /*range-start*/3 + 3/*range-end*/ ); }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_lvalue_1.php
<?hh function main(): void { $x = vec[1]; // we do not allow extracting variables for lvalues /*range-start*/$x[0]/*range-end*/ = vec[2]; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_lvalue_2.php
<?hh function main(): void { $x = vec[1]; // we do not allow extracting variables for lvalues list(/*range-start*/$x[0 + 0]/*range-end*/) = vec[2]; }
PHP
hhvm/hphp/hack/test/ide_code_actions/extract_variable/extract_variable_unsafe_1.php
<?hh class A { public function __construct(public bool $b) {} public function toggle_mut_and_ret_false(): bool { $this->b = !$this->b; return false; } } <<__EntryPoint>> function main(): void { $a = new A(false); $x = $a->b || /*range-start*/$a->toggle_mut_and_ret_false()/*range-end*/; var_dump($x); // false // The refactor can change the meaning of the code in a way that is hard to detect. // IntelliJ Kotlin has the same unsafety: https://pl.kotl.in/isarlHogA // $a = new A(false); // $placeholder_ = $a->toggle_mut_and_ret_false(); // $x = $a->b || $placeholder_; // var_dump($x); // true }
hhvm/hphp/hack/test/ide_code_actions/flip_around_comma/dune
(rule (alias ide_code_actions_flip_around_comma) (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/flip_around_comma/HH_FLAGS) (glob_files %{project_root}/hack/test/ide_code_actions/flip_around_comma/*.php) (glob_files %{project_root}/hack/test/ide_code_actions/flip_around_comma/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ide_code_actions/flip_around_comma --program %{exe:../../../src/hh_single_type_check.exe} --flags --ide-code-actions "Flip around comma"))) (alias (name runtest) (deps (alias ide_code_actions_flip_around_comma)))
PHP
hhvm/hphp/hack/test/ide_code_actions/flip_around_comma/flip_around_comma_call_1.php
<?hh function foo(): void { bar(1, /*range-start*//*range-end*/2); } function bar(int $a, int $b): void {}
PHP
hhvm/hphp/hack/test/ide_code_actions/flip_around_comma/flip_around_comma_list_1.php
<?hh function foo(): void { $v = $vec["a", "b"]; list($a, /*range-start*//*range-end*/$b) = $v; }
PHP
hhvm/hphp/hack/test/ide_code_actions/flip_around_comma/flip_around_comma_params_1.php
<?hh class Box<T> { public function __construct(public T $val){} } class Klass { public function foo(Box<int> $a, /*range-start*//*range-end*/int $b): void {} }
PHP
hhvm/hphp/hack/test/ide_code_actions/flip_around_comma/flip_around_comma_params_3.php
<?hh class Klass { // should be no "flip around comma" refactor suggested because only one param public function foo(int $a,/*range-start*//*range-end*/): void {} }
PHP
hhvm/hphp/hack/test/ide_code_actions/flip_around_comma/flip_around_comma_params_4.php
<?hh class Klass { // Don't suggest a "flip around comma" refactor for params where it's hard to calculate positions // Here it's hard to determine a position for "inout". public function foo(int $a, /*range-start*//*range-end*/inout int $b): void {} }
PHP
hhvm/hphp/hack/test/ide_code_actions/flip_around_comma/flip_around_comma_params_5.php
<?hh class Klass { public function __construct( // Don't suggest a "flip around comma" refactor for params where it's hard to calculate positions // Here it's hard to determine a position for "public". public int $a, int $b = 3, /*range-start*//*range-end*/?int $c = null ): void {} }
hhvm/hphp/hack/test/ide_code_actions/inline_method/dune
(rule (alias ide_code_actions_inline_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/inline_method/HH_FLAGS) (glob_files %{project_root}/hack/test/ide_code_actions/inline_method/*.php) (glob_files %{project_root}/hack/test/ide_code_actions/inline_method/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ide_code_actions/inline_method --program %{exe:../../../src/hh_single_type_check.exe} --flags --ide-code-actions "Inline method"))) (alias (name runtest) (deps (alias ide_code_actions_inline_method)))
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_async_1.php
<?hh class A { private async function inline_me(string $param_a): Awaitable<string> { $z = $param_a; return $z; } public async function main(): Awaitable<void> { echo "test\n"; $s = await $this->/*range-start*/inline_me/*range-end*/("hello "); echo $s . "\n"; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_dupe_1.php
<?hh class A { // ensure we handle repeated method names gracefully // by not providing the refactor public function repeat() {} public function repeat() {} private async function inline_me(string $param_a): Awaitable<string> { $z = $param_a; return $z; } public async function main(): Awaitable<void> { echo "test\n"; $s = await $this->/*range-start*/inline_me/*range-end*/("hello "); echo $s . "\n"; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_empty_block.php
<?hh class Klass { // ensure we gracefully handle an empty block, which can have weird positions (Pos.none) private function foo(): void {} public function bar(): void { $this->/*range-start*/foo/*range-end*/(); } }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_format_1.php
<?hh class A { private function inline_me(string $param_a, int $param_b): string { $z = $param_a; if ($param_b > 1) { $z = $param_a . $param_b; } return $z; } public function main(): void { if (true) { echo "test\n"; $s = $this->/*range-start*/inline_me/*range-end*/("hello " . "world", 2 + 2); echo $s . "\n"; } } }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_hygiene_1.php
<?hh class A { private function inline_me(string $x): string { $z_ = $x; $y = $x."\n"; return $y; } public function foo(): void { $x = 1; "hello " . $this->/*range-start*/inline_me/*range-end*/("world"); $z_ = 2; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_no_inline_2.php
<?hh class A { // not inlineable because it has an inout param private function do_not_inline_me(inout string $_): string { if (1 < 2) { return "first return"; } else { return "second return"; } } public function foo(): void { $this->/*range-start*/do_not_inline_me/*range-end*/(); } }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_no_inline_3.php
<?hh class A { // not inlineable because it has a readonly param (easier to skip) private function do_not_inline_me(readonly int $_): string { if (1 < 2) { return "first return"; } else { return "second return"; } } public function foo(): void { $this->/*range-start*/do_not_inline_me/*range-end*/(); } }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_no_inline_4.php
<?hh class A { // not inlineable because it is non-private. // Our infra currently can't see beyond the current file, so we don't // know if hte function is called elsewhere (even statically). protected function do_not_inline_me(readonly int $_): string { if (1 < 2) { return "first return"; } else { return "second return"; } } public function foo(): void { $this->/*range-start*/do_not_inline_me/*range-end*/(); } }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_params_and_return_1.php
<?hh class A { private function inline_me(string $a, string $b): string { $x = 3; $z = $a . $b; return $z; } public function foo(): void { $x = 2; $s = $this->/*range-start*/inline_me/*range-end*/("a", "b"); } }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_params_and_return_2.php
<?hh class A { private function inline_me(): void { $x = 3; $z = $a . $b; echo $z; } public function foo(): void { // We remove the call when it's to a void function. $this->/*range-start*/inline_me/*range-end*/(); echo "done"; } }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_self_1.php
<?hh class A { private static function inline_me(int $i): string { $z = 2; return $i + $z; } public static function foo(): void { 1 + self::/*range-start*/inline_me/*range-end*/(1); } }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_method/inline_method_static_1.php
<?hh class A { private static function inline_me(int $i): string { $z = 2; return $i + $z; } public static function foo(): void { 1 + static::/*range-start*/inline_me/*range-end*/(1); } }
hhvm/hphp/hack/test/ide_code_actions/inline_variable/dune
(rule (alias ide_code_actions_inline_variable) (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/inline_variable/HH_FLAGS) (glob_files %{project_root}/hack/test/ide_code_actions/inline_variable/*.php) (glob_files %{project_root}/hack/test/ide_code_actions/inline_variable/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ide_code_actions/inline_variable --program %{exe:../../../src/hh_single_type_check.exe} --flags --ide-code-actions "Inline variable"))) (alias (name runtest) (deps (alias ide_code_actions_inline_variable)))
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_variable/inline_variable_3.php
<?hh function foo(): void { $y = 3; $x = $y var_dump(/*range-start*/$x/*range-end*/); }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_variable/inline_variable_4.php
<?hh function foo(): void { $y = 3; $x = $y $y = 6; // inlining $x would change behavior because $y was reassigned var_dump(/*range-start*/$x/*range-end*/); }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_variable/inline_variable_5.php
<?hh class Klass { public int $value = 3; } <<__EntryPoint>> function main(): void { $y = 1; $x = $y + 3; $y = 2; $x = 5; // OK to inline this definition /*range-start*/$x/*range-end*/; }
PHP
hhvm/hphp/hack/test/ide_code_actions/inline_variable/inline_variable_6.php
<?hh function foo(): void { $x = 5; // don't inline $x because used more than once $y = $x; var_dump(/*range-start*/$x/*range-end*/); }
hhvm/hphp/hack/test/ide_code_actions/no_experimental_capabilities/dune
(rule (alias ide_code_actions_no_experimental_capabilities) (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/no_experimental_capabilities/HH_FLAGS) (glob_files %{project_root}/hack/test/ide_code_actions/no_experimental_capabilities/*.php) (glob_files %{project_root}/hack/test/ide_code_actions/no_experimental_capabilities/*.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ide_code_actions/no_experimental_capabilities --program %{exe:../../../src/hh_single_type_check.exe} --flags --ide-code-actions-no-experimental-capabilities "Extract into method"))) (alias (name runtest) (deps (alias ide_code_actions_no_experimental_capabilities)))
PHP
hhvm/hphp/hack/test/ide_code_actions/no_experimental_capabilities/no_experimental_capabilities_extract_method_1.php
<?hh class A { public function foo(int $x): void { // The extracted method should *NOT* contain snippets (like `${0:placeholder}`), // because we are passing `--ide-code-actions-no-experimental-capabilities` to simulate // a client that doesn't have client experimental capability `snippetTextEdit` /*range-start*/ $y = $x + 1; $z = $y + 1; /*range-end*/ $zz = $z; } }
PHP
hhvm/hphp/hack/test/ifc/analyse/basics.php
<?hh // strict <<__InferFlows>> function binop(int $x, int $y): int { return $x + 1; } <<__InferFlows>> function assign0(int $arg): int { $x = $arg; $x = 10; return $x; } <<__InferFlows>> function assign1(int $arg): int { $x = $arg; $x = $x + 10; return $x; } <<__InferFlows>> function condition(int $a0, int $a1, int $a2): int { if ($a2 > 0) { $x = $a0; } else { $x = $a1; } return $x; }
PHP
hhvm/hphp/hack/test/ifc/analyse/binop.php
<?hh class A { } class B extends A { } <<__InferFlows>> function add((int|float) $x, int $y): (int|float) { return $x + $y; } <<__InferFlows>> function qq(?B $x, A $y): A { return $x ?? $y; } <<__InferFlows>> function le_datetime(DateTime $x, DateTime $y): bool { return $x <= $y; } <<__InferFlows>> function diff(B $x, A $y): bool { return $x != $y; } <<__InferFlows>> function eqeqeq(B $x, A $y): bool { return $x === $y; } <<__InferFlows>> function is_((A | int | shape('fld' => int)) $x): bool { return $x is B; }
PHP
hhvm/hphp/hack/test/ifc/analyse/default_args.php
<?hh class C { <<__InferFlows>> public function __construct(public int $i, public int $j = 42) { } } <<__InferFlows>> function constructor_with_default_omitted(int $x): void { new C($x); } <<__InferFlows>> function constructor_with_default_supplied(int $x, int $y): void { new C($x, $y); } <<__InferFlows>> function f(int $i, int $j = 42): void { } <<__InferFlows>> function function_with_default_omitted(int $x): void { f($x); }
hhvm/hphp/hack/test/ifc/analyse/dune
(rule (alias ifc) (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/ifc/analyse/*.php) (glob_files %{project_root}/hack/test/ifc/analyse/*.php.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ifc/analyse --program %{exe:../../../src/hh_single_type_check.exe} --in-extension .php --flags --like-type-hints --union-intersection-type-hints --ifc analyse "" --error-format plain))) (alias (name runtest) (deps (alias ifc)))
PHP
hhvm/hphp/hack/test/ifc/analyse/foreach.php
<?hh <<__InferFlows>> function dict_lit_flow(): void { foreach (dict<string,int>[] as $key => $value) { } } <<__InferFlows>> function dict_var_flow(dict<string,int> $dict): void { foreach ($dict as $key => $value) { } } <<__InferFlows>> function vec_lit_flow(): void { foreach (vec<int>[] as $value) { } } <<__InferFlows>> function vec_var_flow(vec<int> $vec): void { foreach ($vec as $value) { } } <<__InferFlows>> function keyset_lit_flow(): void { foreach (keyset<int>[] as $value) { } } <<__InferFlows>> function keyset_var_flow(keyset<int> $keyset): void { foreach ($keyset as $value) { } }
PHP
hhvm/hphp/hack/test/ifc/analyse/higher_order_functions.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. <<__InferFlows>> function apply((function(int): int) $f): int { return $f(0); }
PHP
hhvm/hphp/hack/test/ifc/analyse/property.php
<?hh // strict class Other { <<__Policied("oBool")>> public bool $oBool = false; public string $oString = 'Hi there!'; } class My { <<__InferFlows>> public function __construct( <<__Policied("mInt")>> public int $mInt, <<__Policied("other")>> public Other $other, public bool $mBool, ) { } <<__InferFlows>> public function getMInt(): int { return $this->mInt; } <<__InferFlows>> public function setMInt(int $candidate): void { $this->mInt = $candidate; } } <<__InferFlows>> function tlGetMyInt(My $obj): int { return $obj->mInt; } <<__InferFlows>> function tlSetMyInt(My $obj, int $val): void { $obj->mInt = $val; } <<__InferFlows>> function tlGetOther(My $obj): Other { return $obj->other; } <<__InferFlows>> function tlGetOtherBool(My $obj): bool { return $obj->other->oBool; } <<__InferFlows>> function tlSetOtherBool(My $obj, bool $bool): void { $obj->other->oBool = $bool; }
PHP
hhvm/hphp/hack/test/ifc/analyse/purpose.php
<?hh // strict class D { <<__InferFlows>> public function __construct(public int $di) {} } class C { <<__InferFlows>> public function __construct( <<__Policied("Secret")>> public int $ci, <<__Policied("Secret")>> public D $d, ) { } <<__InferFlows>> public function getShallow1(): int { return $this->ci; } <<__InferFlows>> public function getShallow2(): D { return $this->d; } <<__InferFlows>> public function getDeep(): int { return $this->d->di; } <<__InferFlows>> public function writeDeep(): void { $this->d->di = 42; } }
PHP
hhvm/hphp/hack/test/ifc/analyse/recursive_class.php
<?hh // strict class R { <<__InferFlows>> public function __construct( public int $prop, public R $r, ) { } <<__InferFlows>> public function recursiveGet(): int { return $this->r->r->r->prop; } <<__InferFlows>> public function recursiveWrite(): void { $this->r->r->r->prop = 42; } }
PHP
hhvm/hphp/hack/test/ifc/analyse/subtype.php
<?hh // strict // elementary subtyping tests class A { } class B extends A { } class C extends B { } // nominal subtyping <<__InferFlows>> function B_A( B $x): A { return $x; } <<__InferFlows>> function C_A( C $x): A { return $x; } // null & mixed & option <<__InferFlows>> function nonnull_mixed( nonnull $x): mixed { return $x; } <<__InferFlows>> function int_opt_int( int $x): ?int { return $x; } <<__InferFlows>> function null_opt_int( null $x): ?int { return $x; } <<__InferFlows>> function A_opt_A( A $x): ?A { return $x; } <<__InferFlows>> function null_opt_A( null $x): ?A { return $x; } <<__InferFlows>> function A_mixed( A $x): mixed { return $x; } <<__InferFlows>> function null_mixed( null $x): mixed { return $x; } // dict <<__InferFlows>> function dict_prim_key (dict<string,bool> $x): dict<arraykey,bool> { return $x; } <<__InferFlows>> function dict_class_key (dict<string,C> $x): dict<arraykey,C> { return $x; } <<__InferFlows>> function dict_kt (dict<string,C> $x): KeyedTraversable<arraykey,C> { return $x; } // vec <<__InferFlows>> function vec_prim_vec_mixed (vec<bool> $x): vec<mixed> { return $x; } <<__InferFlows>> function vec_B_vec_A (vec<B> $x): vec<A> { return $x; } <<__InferFlows>> function vec_kt (vec<C> $x): KeyedTraversable<int,C> { return $x; } // keyset <<__InferFlows>> function keyset_key (keyset<int> $x): keyset<arraykey> { return $x; } <<__InferFlows>> function keyset_kt (keyset<int> $x): KeyedTraversable<int,int> { return $x; }
PHP
hhvm/hphp/hack/test/ifc/analyse/tuple.php
<?hh class C {} <<__InferFlows>> function triple(int $i, C $c): (int,string,C) { return tuple($i, "hello", $c); } <<__InferFlows>> function nested(int $i, C $c): (int,(string,C)) { return tuple($i, tuple("hello", $c)); }
PHP
hhvm/hphp/hack/test/ifc/analyse/unpolicied_fields.php
<?hh // strict class C { <<__InferFlows>> public function __construct( <<__Policied("PUBLIC")>> public int $cx, public int $cy, public D $cd, ) { } <<__InferFlows>> public function testGetUnpolicied(): D { return $this->cd; } <<__InferFlows>> public function testSetMultipleUnpolicied(D $d): void { $this->cy = 42; $this->cd = $d; } <<__InferFlows>> public function testSetDeep(int $i): void { $this->cd->di = $i; } } class D { <<__InferFlows>> public function __construct(public int $di) {} }
PHP
hhvm/hphp/hack/test/ifc/analyse/vec.php
<?hh // strict <<__InferFlows>> function empty(): vec<int> { return vec[]; } <<__InferFlows>> function collection(): vec<string> { return vec["hi", "there"]; } <<__InferFlows>> function add(vec<int> $vec): void { $vec[] = 2; } <<__InferFlows>> function retElem(vec<int> $vec): int { return $vec[1]; }
PHP
hhvm/hphp/hack/test/ifc/analyse/vec_element_union_by_assignment.php
<?hh class A {} function testClass(vec<int> $v, A $x): void { $v[] = $x; } function testPrim(vec<int> $v, string $x): void { $v[] = $x; }
PHP
hhvm/hphp/hack/test/ifc/analyse/while.php
<?hh // strict <<__InferFlows>> function simple(bool $b, string $s1, string $s2): arraykey { $x = ""; while ($b) { $x = $s1; $x = $s2; } return $x; } <<__InferFlows>> function union(bool $b, int $i, string $s1, string $s2): arraykey { $x = $i; while ($b) { $x = $s1; $x = $s2; } return $x; } <<__InferFlows>> function breaks(bool $b, int $i, string $s1, string $s2): arraykey { $x = $i; while ($b) { $x = $s1; if ($b) break; $x = $s2; } return $x; } <<__InferFlows>> function continues(bool $b, int $i, string $s1, string $s2): arraykey { $x = $i; while ($b) { $x = $s1; if ($b) continue; $x = $s2; } return $x; }
PHP
hhvm/hphp/hack/test/ifc/check/array_subtyping.php
<?hh class Simple { <<__Policied("INDEX")>> public int $ix = 42; <<__Policied("VALUE")>> public string $value = "hello"; public vec<string> $vec = vec[]; <<__Policied("KEYED_TRAVERSABLE")>> public KeyedTraversable<int,string> $keyedTraversable = vec[]; <<__Policied("KEYED_CONTAINER")>> public KeyedContainer<int,string> $keyedContainer = vec[]; <<__InferFlows>> public function vecToKT(): void { $this->vec[$this->ix] = $this->value; // INDEX flows to KEYED_TRAVERSABLE // VALUE flows to KEYED_TRAVERSABLE $this->keyedTraversable = $this->vec; } <<__InferFlows>> public function vecToKC(): void { $this->vec[$this->ix] = $this->value; // INDEX flows to KEYED_TRAVERSABLE // VALUE flows to KEYED_TRAVERSABLE $this->keyedContainer = $this->vec; } }
PHP
hhvm/hphp/hack/test/ifc/check/as.php
<?hh // strict class Data { <<__Policied("PUBLIC")>> public bool $pub = true; <<__Policied("PRIVATE")>> public bool $pri = false; } class C {} class D {} <<__InferFlows>> function as_exn_leak(Data $data, C $c, D $d): void { if ($data->pri) { $x = $c; } else { $x = $d; } try { $x as C; // may throw } catch (Exception $_) { $data->pub = true; } } <<__InferFlows>> function as_null_exn_ok(Data $data, C $c, D $d): void { if ($data->pri) { $x = $c; } else { $x = $d; } try { $x ?as C; // no exception is thrown } catch (Exception $_) { $data->pub = true; } } <<__InferFlows>> function as_null_exn_ko(Data $data, C $c, D $d): void { if ($data->pri) { $x = $c; } else { $x = $d; } $data->pub = !($x ?as C); }
PHP
hhvm/hphp/hack/test/ifc/check/async_await.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class C { <<__Policied("A")>> public int $a = 0; <<__Policied("B")>> public int $b = 0; } <<__InferFlows>> async function plus(int $x, int $y): Awaitable<int> { return $x + $y; } <<__InferFlows>> async function store_a_in_b (C $c): Awaitable<void> { $c->b = await plus($c->a, 2); } <<__InferFlows>> async function store_a_in_b_lambda (C $c): Awaitable<void> { $f = async $x ==> { $c->b = $x; }; await $f($c->a); }
PHP
hhvm/hphp/hack/test/ifc/check/await_all.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class C { <<__Policied("A")>> public int $a = 0; <<__Policied("B")>> public int $b = 0; } <<__InferFlows>> async function plus(int $x, int $y): Awaitable<int> { return $x + $y; } <<__InferFlows>> async function illegal_access(C $c): Awaitable<void> { $c->a = $c->b; return; } <<__InferFlows>> async function store_a_in_b (C $c): Awaitable<void> { concurrent { $c->b = await plus($c->a, 2); // illegal access $c->a = await plus($c->a, 3); // ok await illegal_access($c); //illegal access } }
PHP
hhvm/hphp/hack/test/ifc/check/await_all_scope.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class C { <<__Policied("A")>> public int $a = 0; <<__Policied("B")>> public int $b = 0; } <<__InferFlows>> async function plus(int $x, int $y): Awaitable<int> { return $x + $y; } <<__InferFlows>> async function does_nothing(C $c): Awaitable<void> { return; } <<__InferFlows>> async function leak_x (C $c): Awaitable<void> { concurrent { $x = await plus($c->a, 2); await does_nothing($c); } $c->b = $x; //illegal access }
PHP
hhvm/hphp/hack/test/ifc/check/calls_basics.php
<?hh // strict class C { <<__Policied("A")>> public int $a = 0; <<__Policied("B")>> public int $b = 0; <<__InferFlows>> public function setb(int $n): void { $this->b = $n; } <<__InferFlows>> public function is_a_pos(): bool { if ($this->a > 0) { return true; } else { return false; } } } <<__InferFlows>> function dbl(int $x): int { $x += $x; return $x; } <<__InferFlows>> function flow_a_to_b(C $c): void { $n = dbl($c->a); $c->setb($n); } <<__InferFlows>> function flow_b_to_b(C $c): void { $c->setb($c->b); } <<__InferFlows>> function flow_bot_to_b(C $c): void { $c->setb(dbl(dbl(42))); } <<__InferFlows>> function indirect_flow_a_to_b(C $c): void { if ($c->a > 0) { $c->setb(42); } } <<__InferFlows>> function indirect_flow_a_to_b_bis(C $c1, C $c2): void { if ($c1->is_a_pos()) { $c2->setb($c2->b + 1); } }
PHP
hhvm/hphp/hack/test/ifc/check/calls_static.php
<?hh class X { <<__InferFlows>> public function __construct( <<__Policied("PUBLIC")>> public int $public, <<__Policied("PRIVATE")>> public int $private, ) {} <<__InferFlows>> public static function flow(X $x): void { $x->public = $x->private; } <<__InferFlows>> public function testKOSelf(X $x): void { self::flow($x); // Flow error } <<__InferFlows>> public function testKOAbsolute(X $x): void { X::flow($x); // Flow error } <<__InferFlows>> public function testOK(X $x): void { Y::flow($x); } } class Y extends X { <<__InferFlows>> public static function flow(X $x): void { } <<__InferFlows>> public function testKOAbsolute(X $x): void { Y::flow($x); // Flow error } <<__InferFlows>> public function testKOParent(X $x): void { parent::flow($x); // Flow error } <<__InferFlows>> public function testOK(X $x): void { Y::flow($x); self::flow($x); } }
PHP
hhvm/hphp/hack/test/ifc/check/catch.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class X { <<__Policied("A")>> public int $a = 0; <<__Policied("B")>> public int $b = 1; } <<__InferFlows>> function leak_pc_in_catch(X $x, Exception $e): void { try { if ($x->a > 0) throw $e; } catch (Exception $exn) { // This leaks A via the pc $x->b = 12; } } <<__InferFlows>> function do_not_leak_pc_after_catch(X $x, Exception $e): void { try { if ($x->a > 0) throw $e; } catch (Exception $_) {} // We will reach this code whether or not the exception was thrown. // so there is no violation $x->b = 1; } <<__InferFlows>> function nested_try(X $x, Exception $e): void { try { if ($x->a > 0) throw $e; try {} catch (Exception $_) {} } catch (Exception $_) { // This should leak A via the PC $x->b = 0; } } <<__InferFlows>> function throw_in_catch(X $x, Exception $e): void { try { throw $e; } catch (Exception $_) { if ($x->a > 0) throw $e; } $x->b = 1; }
PHP
hhvm/hphp/hack/test/ifc/check/catch_multi.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class X { <<__Policied("A")>> public int $a = 0; <<__Policied("B")>> public int $b = 1; } class E1 extends Exception {} class E2 extends Exception {} <<__InferFlows>> function no_catch_all(X $x, E2 $e): void { try { if ($x->a > 0) throw $e; } catch (E1 $_) {} // This leaks A via the PC $x->b = 0; } <<__InferFlows>> function store_in_finally(X $x, E1 $e): void { try { if ($x->a > 0) throw $e; } finally { // This is ok because finally runs regardless of exceptions $x->b = 123; } } <<__InferFlows>> function return_in_try(X $x, E1 $e): void { try { if ($x->a > 0) return; } finally { // This is ok $x->b = 123; } } <<__InferFlows>> function multi_catch(X $x, E1 $e): void { try { if ($x->a > 0) throw $e; } catch (E1 $_) { $x->b = 1; } catch (E2 $_) { $x->b = 2; } } <<__InferFlows>> function no_catch(X $x, E1 $e, bool $b): void { try { $val = 0; if ($b) { $val = $x->a; throw $e; } $val = $x->b; } finally { // This should be an error $x->b = $val; } } <<__InferFlows>> function throw_in_catch(X $x, E1 $e): void { try { if ($x->a > 0) throw $e; } catch (Exception $e) { throw $e; } finally {} // This leaks the pc because we rethrow the exception $x->b = 123; } <<__InferFlows>> function local_bindings(bool $b, Exception $e): int { try { try { if ($b) { $x = 0; throw $e; } } catch (E1 $_) { } } catch (Exception $_) { return $x; } return 0; } <<__InferFlows>> function unreachable_assign(X $x, Exception $e): void { $val = 0; try { throw $e; } catch (Exception $_) { $val = $x->a; throw $e; $val = 0; } finally { // This leaks A into B $x->b = $val; } }
PHP
hhvm/hphp/hack/test/ifc/check/class_generics.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class A<T> { <<__InferFlows>> public function __construct( <<__Policied("A")>> public T $a ) {} } class B<T> { <<__InferFlows>> public function __construct( <<__Policied("B")>> public T $b ) {} } // Identity function that forces input to have policy A <<__InferFlows>> function identity<T>(T $x): T { $a = new A($x); return $a->a; } <<__InferFlows>> function write_a_to_b(): B<int> { // Illegal because the output of identity has policy A return new B(identity(1)); } <<__InferFlows>> function leak_b_to_a(B<int> $x): int { // Illegal because the input to identity must flow to A return identity($x->b); } <<__InferFlows>> function f(): void { $x = new A(new B(0)); // Pulling the int out of $x will have the join of both policies $y = new A($x->a->b); // no $z = new B($x->a->b); // no }
PHP
hhvm/hphp/hack/test/ifc/check/conditional_exprs.php
<?hh class A { <<__Policied("PUBLIC")>> public ?int $pub = 0; <<__Policied("PRIVATE")>> public ?int $pri = 0; } <<__InferFlows>> function wpub(A $a): int { $a->pub = 10; return 10; } <<__InferFlows>> function wpri(A $a): int { $a->pri = 10; return 10; } <<__InferFlows>> function ok(A $a): void { $a->pri ?? wpri($a); $a->pri ?? wpri($a); $a->pri ?: wpri($a); ($a->pub ?? wpub($a)) + wpri($a); $a->pub ?? wpri($a); $a->pub ? wpub($a) : wpri($a); $a->pub ? wpri($a) : wpub($a); } <<__InferFlows>> function ko0(A $a): void { $a->pri ?? wpub($a); } <<__InferFlows>> function ko1(A $a): void { $a->pri ? 0 : wpub($a); } <<__InferFlows>> function ko2(A $a): void { $a->pub = ($a->pri ?? 0); } <<__InferFlows>> function ko3(A $a, int $i): void { $a->pub = ($i ?? $a->pri); } <<__InferFlows>> function ko4(A $a, bool $b): void { $a->pub = ($b ? $a->pri : 0); } <<__InferFlows>> function ko5(A $a, bool $b): void { $a->pub = ($b ? 0 : $a->pri); }
PHP
hhvm/hphp/hack/test/ifc/check/darray.php
<?hh class C { <<__Policied("PUBLIC")>> public int $public = 0; <<__Policied("PRIVATE")>> private int $private = 0; public function __construct( <<__Policied("PUBLIC")>> public darray<int,int> $dPublic, <<__Policied("PRIVATE")>> public darray<int,int> $dPrivate, ) {} <<__InferFlows>> public function subtypeKeyKO(): void { // PRIVATE leaks to PUBLIC $this->dPublic = darray[$this->private => 42]; } <<__InferFlows>> public function subtypeValKO(): void { // PRIVATE leaks to PUBLIC $this->dPublic = darray[42 => $this->private]; } <<__InferFlows>> public function subtypeOK(): void { $this->dPublic = darray[42 => 42]; } <<__InferFlows>> public function accessKO(): void { // PRIVATE leaks to PUBLIC $this->public = $this->dPrivate[0]; } <<__InferFlows>> public function accessOK(): void { $this->public = $this->dPublic[0]; } <<__InferFlows>> public function overrideValKO(): void { // PRIVATE leaks to PUBLIC $this->dPublic[0] = $this->private; } <<__InferFlows>> public function overrideKeyKO(): void { // PRIVATE leaks to PUBLIC $this->dPublic[$this->private] = 0; } <<__InferFlows>> public function overrideOK(): void { $this->dPublic[0] = 42; } }
PHP
hhvm/hphp/hack/test/ifc/check/dict.php
<?hh // strict class Basic { <<__Policied("S")>> public string $string = "string"; <<__Policied("B")>> public bool $bool = false; <<__Policied("D")>> public dict<string,bool> $dict = dict[]; <<__InferFlows>> public function set(): void { // B flows into D through dictionary value $this->dict["ludwig"] = $this->bool; } <<__InferFlows>> public function collection(): void { // B flows into D through dictionary value // S flows into D through dictionary key $this->dict = dict[$this->string => $this->bool]; } <<__InferFlows>> public function mutationKeyLeak(): void { $this->dict[$this->string] = false; // S leaks to D through the key } <<__InferFlows>> public function accessKeyLeak(dict<string, bool> $dict): void { $this->bool = $dict[$this->string]; // S leaks to B } } class COW { <<__InferFlows>> public function __construct( <<__Policied("X")>> public bool $x, <<__Policied("Y")>> public bool $y, <<__Policied("DICT")>> public dict<string,bool> $dict, ) {} <<__InferFlows>> public function copyOnWrite(dict<string, bool> $dict): void { $dict["x"] = $this->x; // X flows into DICT through dictionary value $this->dict = $dict; $dict["y"] = $this->y; // Y doesn't flow into DICT because dict has copy-on-write semantics } }
hhvm/hphp/hack/test/ifc/check/dune
(rule (alias ifc) (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/ifc/check/*.php) (glob_files %{project_root}/hack/test/ifc/check/*.php.exp)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/ifc/check --program %{exe:../../../src/hh_single_type_check.exe} --in-extension .php --flags --like-type-hints --ifc check "" --error-format plain))) (alias (name runtest) (deps (alias ifc)))
PHP
hhvm/hphp/hack/test/ifc/check/dynamic.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class C { <<__Policied("PRIVATE")>> public ~int $priv = 0; <<__Policied("PUBLIC")>> public ~int $pub = 0; } <<__SupportDynamicType>> class A { public int $val = 0; } <<__InferFlows>> function write_b(dynamic $d, C $c): void { $c->pub = $d; } <<__InferFlows>> function simple_write(C $c): void { write_b($c->priv, $c); } <<__InferFlows>> function write_private(dynamic $d, C $c): void { $d->val = $c->priv; } <<__InferFlows>> function write_public(dynamic $d, C $c): void { $d->val = $c->pub; } <<__InferFlows>> function read_dyn(dynamic $d): ~int { return $d->val; } <<__Policied("PUBLIC")>> function complex_write(A $a, C $c): void { // All inputs have public lump write_public($a, $c); // ok write_private($a, $c); // illegal } <<__Policied("PRIVATE")>> function complex_read(A $a, C $c) : void { $c->priv = read_dyn($a); // ok, anything can be stored in priv $c->pub = read_dyn($a); // illegal! $a has a private lump }
PHP
hhvm/hphp/hack/test/ifc/check/early_return.php
<?hh // strict class PublicData { <<__InferFlows>> public function __construct( <<__Policied("PUBLIC")>> public string $data, ) {} } class PoliciedData { <<__InferFlows>> public function __construct( <<__Policied("SECRET")>> public bool $data, ) {} } <<__InferFlows>> function earlyReturn(PoliciedData $x, PublicData $y): void { if ($x->data) { return; } $y->data = "String"; }
PHP
hhvm/hphp/hack/test/ifc/check/exceptions.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class X { <<__InferFlows>> public function __construct(<<__Policied("PRIVATE")>> public int $valuex) {} } class Y { <<__InferFlows>> public function __construct(<<__Policied("PUBLIC")>> public int $valuey) {} } <<__InferFlows>> function g(X $x, Y $y): void { if ($x->valuex > 10) { throw new Exception("test"); } $y->valuey = 10; }
PHP
hhvm/hphp/hack/test/ifc/check/exception_multi_function.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class C { <<__Policied("A")>> public int $a = 0; <<__Policied("B")>> public int $b = 0; } <<__InferFlows>> function f(C $x, Exception $e): void { if ($x->a > 0) { throw $e; } } <<__InferFlows>> function f2(C $x, Exception $e): void { f($x, $e); } <<__InferFlows>> function g(C $x, Exception $e): void { try { // f() may throw depending on the the value A f($x, $e); } catch (Exception $_) { // If f() threw, then the PC here is dependent on A $x->b = 1234; } } <<__InferFlows>> function g2(C $x, Exception $e): void { try { // f2() may throw depending on the the value A f2($x, $e); } catch (Exception $_) { // If f() threw, then the PC here is dependent on A $x->b = 1234; } }
PHP
hhvm/hphp/hack/test/ifc/check/exception_subtyping.php
<?hh class MyException extends Exception {} class C { <<__InferFlows>> public function __construct( <<__Policied("PRIVATE")>> public int $private, <<__Policied("PUBLIC")>> public int $public, ) { } } <<__InferFlows>> function leak_via_control(C $c, MyException $e): void { if ($c->private > 10) { throw $e; } $c->public = 10; } <<__InferFlows>> function leak_pc_in_catch(C $c, MyException $e): void { try { if ($c->private > 0) throw $e; } catch (Exception $_) { // This leaks PRIVATE via the pc $c->public = 12; } }
PHP
hhvm/hphp/hack/test/ifc/check/external_args.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class A { public int $value = 0; <<__InferFlows>> public function __construct() {} } class B { public A $a; <<__InferFlows>> public function __construct() { $this->a = new A(); } } <<__Policied>> function read_external(<<__External>> A $x, A $y) : void { // Ok! External flows into the function $y->value = $x->value; } <<__Policied>> function write_external(<<__External>> A $x, A $y) : void { // Illegal! Implicit does not flow into External $x->value = $y->value; } <<__Policied>> function return_external(<<__External>> A $x): A { // Illegal! This implicitly casts the invariant lump return $x; } <<__Policied>> function store_external(<<__External>> A $a, B $b): void { // Illegal! This would make $a mutable $b->a = $a; $b->a->value = 1234; } <<__Policied>> function store_int(A $a, <<__External>> int $x): void { // Ok! Immutable external data can be stored $a->value = $x; } <<__Policied>> function mix_externals(<<__External>> A $x, <<__External>> A $y): void { // Illegal! Externals cannot mix $x->value = $y->value; }
PHP
hhvm/hphp/hack/test/ifc/check/finally_conts.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. class X { <<__Policied("A")>> public int $a = 0; <<__Policied("B")>> public int $b = 1; } <<__InferFlows>> function f(X $x, Exception $e, bool $b): void { $z = 0; try { try { $y = 0; throw $e; } catch (Exception $_) { if ($b) { // In the catch continuation, $y depends on A $y = $x->a; throw $e; } $y = 2; } finally { $z = $y; } } catch (Exception $_) { // Error! In this flow, $z depends on A $x->b = $z; $z = 0; } // This is ok; in the Next continuation, $z does not depend on A $x->b = $z; } <<__InferFlows>> function g(X $x, Exception $e): void { try { try { if ($x->a > 0) throw $e; } finally { // noop } } catch (Exception $_) { $x->b = 0; } }
PHP
hhvm/hphp/hack/test/ifc/check/for.php
<?hh class C { <<__Policied("PRIVATE")>> public int $private = 0; <<__Policied("PUBLIC")>> public int $public = 0; } class D { public function __construct(public C $c) { } } function dont_leak_through_init(D $d): void { // Doesn't leak anything as initialisers are evaluated before the condition for ($d->c->public = 0; $d->c->private === 0;) { } } <<__InferFlows>> function leak_through_incr(C $c): void { // Leaks the private context to public at the increment statement for (;$c->private === 0; $c->public++) { } } <<__InferFlows>> function dont_leak_through_incr_continue(C $c): void { // Doesn't leak because we always continue for (;$c->private === 0;) { continue; $c->public++; } } <<__InferFlows>> function leak_through_incr_continue(C $c): void { // Leaks the private context to public at the increment statement for (;$c->private === 0; $c->public++) { continue; } } <<__InferFlows>> function forever(): int { for (;;) { return 10; } }
PHP
hhvm/hphp/hack/test/ifc/check/foreach.php
<?hh class C { <<__Policied("PUBLIC")>> public int $out = 0; <<__Policied("KEY")>> public int $key = 0; <<__Policied("VALUE")>> public int $value = 0; } <<__InferFlows>> function leak_through_vec_value(C $c): void { $vec = vec[$c->value]; foreach ($vec as $value) { // VALUE leaks into PUBLIC $c->out = $value; } } <<__InferFlows>> function leak_through_dict_key_and_value(C $c): void { $dict = dict[$c->key => $c->value]; foreach ($dict as $key => $value) { // KEY leaks into PUBLIC $c->out = $key; // VALUE leaks into PUBLIC $c->out = $value; } }
PHP
hhvm/hphp/hack/test/ifc/check/foreach_class_value.php
<?hh class D { public bool $data = true; } class C { <<__Policied("B")>> public bool $b = false; <<__Policied("D")>> public ?D $d = null; } <<__InferFlows>> function f(C $c, Traversable<D> $t): void { foreach($t as $d) { // we force $t to contain // objects that are subject to // the policy D $c->d = $d; } foreach($t as $d) { // Bad flow from B to D $d->data = $c->b; } }