language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
PHP
hhvm/hphp/hack/test/decl/classname_in_namespace.php
<?hh namespace { type A = classname<C>; type B = \classname<C>; namespace NS { type A = classname<C>; type B = \classname<C>; } }
PHP
hhvm/hphp/hack/test/decl/class_const_int_literals.php
<?hh class C { const int MY_DECIMAL_INT = 42; const int MY_OCTAL_INT = 0754; const int MY_HEX_INT = 0xFF; const int MY_BINARY_INT = 0b1010; }
PHP
hhvm/hphp/hack/test/decl/class_const_referencing_enum.php
<?hh enum Words: string as string { FOO = 'foo'; BAR = 'bar'; } <<__ConsistentConstruct>> abstract class TestClassConstReferencingEnum { const dict<Words, float> WORD_VALUES = dict[ Words::FOO => 1.0, Words::BAR => 2.0, ]; }
PHP
hhvm/hphp/hack/test/decl/class_const_referencing_global_const.php
<?hh namespace { class Integer { const int MAX32 = INT32_MAX; const int MAX64 = Math\INT64_MAX; } namespace NS { class Integer { const int MAX32 = INT32_MAX; const int MAX64 = Math\INT64_MAX; } } }
PHP
hhvm/hphp/hack/test/decl/class_level_where.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ <<file: __EnableUnstableFeatures('class_level_where')>> class C {} interface I where this as C {} trait PartialC implements I where this = C {} interface J where C super this {}
PHP
hhvm/hphp/hack/test/decl/coeffect_contexts.php
<?hh abstract class C { abstract const ctx C0 = []; abstract const ctx C1 = [zoned_shallow]; abstract const ctx C2 = [zoned_shallow, rx_shallow]; public abstract function f0()[]: void; public abstract function f1()[zoned_shallow]: void; public abstract function f2()[zoned_shallow, rx_shallow] : void; }
PHP
hhvm/hphp/hack/test/decl/coeffect_fun_dependent.php
<?hh function f((function ()[_]: void) $f)[ctx $f]: void {} function f_option(?(function ()[_]: void) $f)[ctx $f]: void {} function f_like(~(function ()[_]: void) $f)[ctx $f]: void {} function f_like_option(~?(function ()[_]: void) $f)[ctx $f]: void {}
PHP
hhvm/hphp/hack/test/decl/coeffect_parameter_dependent.php
<?hh abstract class A { abstract const ctx C; } function f(A $a)[$a::C]: void {} function f_option(?A $a)[$a::C]: void {} function f_like(~A $a)[$a::C]: void {} function f_like_option(~?A $a)[$a::C]: void {}
PHP
hhvm/hphp/hack/test/decl/constants.php
<?hh // We expect some typechecker errors in this one because we want the decl parser // to be more accepting than the typechecker. const string MY_CONST = "my const"; const int MY_CONST2 = 5; const float MY_CONST3 = 5.5; const num MY_CONST5 = 5e1; const bool MY_CONST6 = true; const vec<int> MY_VEC = vec[];
PHP
hhvm/hphp/hack/test/decl/constraints_mentioning_tparams_in_same_list.php
<?hh // strict class E<Ta, Tb> {} interface I< Ta as arraykey, Tb as Ta, Tc as Td, Td as E<Ta, Tf>, Tf, Tarr as varray<Ta>, Tlike as ~Ta, Topt as ?Ta, Tfun as (function(Ta): Tb), Tshape as shape('a' => Ta), Tdarr as darray<Ta, Tb>, Tvarr as varray<Ta>, Tvdarr as varray_or_darray<Ta, Tb>, Ttuple as (Ta, Tb), > {}
PHP
hhvm/hphp/hack/test/decl/constraints_with_fully_qualified_name.php
<?hh type Ta = int; type Td = string; interface I< Ta as arraykey, Tb as Map<Ta, Td>, Tc as Map<\Ta, \Td>, Td, >{}
PHP
hhvm/hphp/hack/test/decl/constraints_with_fully_qualified_name_in_namespace.php
<?hh namespace { type Ta = int; type Te = string; } namespace NS { type Ta = int; type Te = string; interface I< Ta as arraykey, Tb as Map<Ta, Te>, Tc as Map<\Ta, \Te>, Td as Map<\NS\Ta, \NS\Te>, Te, >{} }
PHP
hhvm/hphp/hack/test/decl/consts_misc2.php
<?hh final abstract class TestC { public static function i(int $x)[write_props]: int {return $x;} const int i = 3; } enum TestE: int as int {X = 4; Y = 5;} final abstract class TestRefs1 { const mixed A = shape(TestE::X => 1); // HHVM evaluates [TestE::X] const mixed B = shape(TestE::X => TestE::Y, TestE::Y => 6); // HHVM evaluates [TestE::X, TestE::Y] const mixed C = +TestE::X; // HHVM evaluates [TestE::X] const mixed D = true ? TestE::X : 7; // HHVM evaluates [TestE::X] const mixed E = TestC::class; // HHVM evaluates [] } enum class TestRefs2:mixed { string K1 = "b"; string K2 = "c"; mixed B = shape(TestRefs2::K1 => 1, self::K2 => 2); // HHVM evaluates [TestRefs2::K1, self::K2] mixed F = TestC::i(4); // HHVM evaluates [TestC::i], the function mixed G = TestC::i(TestC::i); // HHVM evaluates [TestC::i, TestC::i] both function and constant mixed H = TestC::i<>; // HHVM evaluates [] }
PHP
hhvm/hphp/hack/test/decl/const_attribute.php
<?hh // strict <<__Const>> class A { public int $x; <<__Const>> public int $y; public function __construct() { $this->x = 4; $this->y = 5; } } class B { <<__Const>> public int $x; public function __construct() { $this->x = 4; } } class C { public function __construct(<<__Const>> private int $x) {} }
PHP
hhvm/hphp/hack/test/decl/const_misc1.php
<?hh enum class A:arraykey { int X = "a"; // decl type of X is \HH\MemberOf<A,int> string Y = 1; // decl type of Y is \HH\MemberOf<A,string> } enum B:int as arraykey { X = 1; // decl type of X is int Y = "hello"; // decl type of Y is string Z = B::X; // decl type of Z is TAny } const int I=1, S="a"; // decl type of I is int, S is int const J=1, T="a"; // decl type of J is int, S is string class C { const int IC = 1, SC = "a"; // decl type of IC is int, SC is int const JC=1, TC = "a"; // decl type of JC is int, TC is string }
PHP
hhvm/hphp/hack/test/decl/const_missing_hint.php
<?hh /* HH_FIXME[2001] */ const CInt = 1; /* HH_FIXME[2001] */ const CBool = true; /* HH_FIXME[2001] */ /* HH_FIXME[2035] */ const Utild = ~1; /* HH_FIXME[2001] */ /* HH_FIXME[2035] */ const Unot = !true; /* HH_FIXME[2001] */ const Uplus = +1; /* HH_FIXME[2001] */ const Uminus = -1; /* HH_FIXME[2001] */ /* HH_FIXME[2035] */ const FromConst = CInt; enum E : int { FromConst = CInt; }
PHP
hhvm/hphp/hack/test/decl/const_string_escaping.php
<?hh class C { const string SINGLE = 'whomst\'d\'ve'; const string DOUBLE = "\n\t"; const string SINGLE_ENDS_IN_SINGLE = 'a\''; const string DOUBLE_ENDS_IN_DOUBLE = "a\""; const string SINGLE_ESCAPED_BACKSLASH = '\\'; const string DOUBLE_ESCAPED_BACKSLASH = "\\"; const string SINGLE_ESCAPED_DOLLAR = '\$'; const string DOUBLE_ESCAPED_DOLLAR = "\$"; const string HEREDOC = <<<EOT \n\t EOT; const string NOWDOC = <<<'EOT' no escape sequences are unescaped: \'\n\t EOT; }
PHP
hhvm/hphp/hack/test/decl/context_alias_declaration.php
<?hh <<file:__EnableUnstableFeatures('context_alias_declaration', 'context_alias_declaration_short')>> newctx X as []; newctx Y as [] = [defaults];
PHP
hhvm/hphp/hack/test/decl/ctx_const_both_bounds.php
<?hh interface WithLowerThenUpperBound { abstract const ctx C super [defaults] as [rx]; } interface WithUpperThenLowerBound { abstract const ctx C as [write_props] super [defaults]; }
PHP
hhvm/hphp/hack/test/decl/ctx_const_lower_bound.php
<?hh abstract class C { abstract const ctx C super [defaults]; } abstract class D { abstract const ctx C super [defaults] = []; }
PHP
hhvm/hphp/hack/test/decl/ctx_const_upper_bound.php
<?hh abstract class C { abstract const ctx C as [write_props]; } abstract class D { abstract const ctx C as [write_props] = [defaults]; }
PHP
hhvm/hphp/hack/test/decl/denotable_unions.php
<?hh //strict // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. <<file: __EnableUnstableFeatures('union_intersection_type_hints')>> interface I {} interface J {} function f((I& J) $_x): void {} function g((I| J) $_x): void {}
PHP
hhvm/hphp/hack/test/decl/deprecated.php
<?hh class DeprecatedClass { <<__Deprecated('use bar() instead')>> public function foo(): void {} <<__Deprecated()>> public function bar(): void {} <<__Deprecated>> public function baz(): void {} <<__Deprecated('use bar2() instead', 5)>> public function foo2(): void {} } <<__Deprecated('use bar() instead')>> function foo(): void {} <<__Deprecated()>> function bar(): void {} <<__Deprecated>> function baz(): void {} <<__Deprecated('use bar2() instead', 5)>> function foo2(): void {}
PHP
hhvm/hphp/hack/test/decl/deprecated_string_concat.php
<?hh <<__Deprecated('single'.'single')>> function singlesingle(): void {} <<__Deprecated("double"."double")>> function doubledouble(): void {} <<__Deprecated('single'."double")>> function singledouble(): void {} <<__Deprecated('single'."double".'single')>> function singledoublesingle(): void {} <<__Deprecated('single'.<<<EOT heredoc EOT )>> function heredoc(): void {} <<__Deprecated('single'.<<<'EOT' nowdoc EOT )>> function nowdoc(): void {}
PHP
hhvm/hphp/hack/test/decl/deprecated_string_escaping.php
<?hh <<__Deprecated('can\'t write an apostrophe without escaping in single quotes')>> function single(): void {} <<__Deprecated("other escapes like \n and \t available in double quotes")>> function double(): void {}
PHP
hhvm/hphp/hack/test/decl/dynamically_callable.php
<?hh // strict /** * Copyright (c) 2019, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ class X { <<__DynamicallyCallable>> public function pub(): void {} }
PHP
hhvm/hphp/hack/test/decl/enum_class.php
<?hh type write_props = \HH\Capabilities\WriteProperty; enum class A:arraykey { int X = 1; int Y = B::Y; int Z = true ? 3 : B::Y; int W = C::w(); } enum class B:string { arraykey Y = 2; } class C { public static function w()[write_props]:int {return 1;} }
PHP
hhvm/hphp/hack/test/decl/enum_constraint.php
<?hh enum A : string as string {X='a';} enum B : int as IdOf<X> {X=1;} enum C : int as arraykey {X=1;} newtype N as arraykey = int; enum D : int as N {X=1; Y="a";} enum E : C as C {X=C::X;}
PHP
hhvm/hphp/hack/test/decl/explicit_type_collection.php
<?hh // strict class A implements HH\ClassAttribute { public function __construct(public vec<mixed> $i) {} } <<A(vec<int>[1, 2, 3])>> class Foo { const string KEY = 'key'; } <<A(vec<shape( Foo::KEY => (int, string, dict<mixed, keyset<classname<Foo>>>), )>[])>> class Bar {}
PHP
hhvm/hphp/hack/test/decl/file_mode.php
<?hh class MyPartialClass {} function my_partial_function(): void {} type MyPartialType = string; const MyPartialType MY_PARTIAL_CONST = "make sure we're properly tracking the file mode";
PHP
hhvm/hphp/hack/test/decl/functions.php
<?hh function simple_function(): void {} function simple_int_function(): int { return 5; } function simple_function_with_body(): float { return 0.5; } function function_with_args(int $arg1, float $arg2): void {} type Typedef = string; function function_with_non_primitive_args(Typedef $arg1): Typedef { return $arg1; } function test_generic_fun<T>(T $arg1): T { return $arg1; } function test_constrained_generic_fun<T1 super int, T2 as string>( T1 $arg1, T2 $arg2, ): T1 { return $arg1; } function test_returns_generic(): HH\Traversable<int> { return vec[5]; } function takes_optional(?int $x): void {} function in_out(inout int $x): void {} function takes_returns_function_type<Tu>( Tu $x, (function(Tu): void) $unused, ): (function((function(Tu): void)): void) { return $x ==> { return; }; } function takes_returns_dict(dict<string, bool> $m): dict<string, bool> { return $m; } class C {} function null_type_hint<T as nothing>(?T $x): null { return $x; } function resource_type_hint(resource $i): resource { return $i; // ok } function noreturn_type_hint(): noreturn { while (true) { } } function variadic_function(mixed ...$args): void { }
PHP
hhvm/hphp/hack/test/decl/function_where_constraints.php
<?hh // strict class Cov<+Tc> {} class A {} class Base<Tb> { public function foo<Tf as A>(): void where Tb as Cov<Tf> {} } class Derived<Td> extends Base<Cov<Td>> { public function foo<Tf as A>(): void where Td as A {} }
PHP
hhvm/hphp/hack/test/decl/generic_classes.php
<?hh class Bag<T> { private T $data; public function __construct(T $data): void { $this->data = $data; } public function get(): T { return $this->data; } } class ContravariantBag<-T> { private T $data; public function __construct(T $data): void { $this->data = $data; } } class CovariantBag<+T> { private T $data; public function __construct(T $data): void { $this->data = $data; } public function get(): T { return $this->data; } }
PHP
hhvm/hphp/hack/test/decl/generic_method_tparam_scope.php
<?hh // strict class C { public function f<Ta>(Ta $a): Ta { return $a; } public function g<Tb>(Tb $b): Tb { return $b; } }
HTML Help Workshop
hhvm/hphp/hack/test/decl/hhi.hhi
<?hh type X = int; const int Y = 0; function f(string $s): int; class C { public function g(X $x): int; }
hhvm/hphp/hack/test/decl/HH_FLAGS
--auto-namespace-map '{"Dict":"HH\\Lib\\Dict"}' --enable-xhp-class-modifier --like-type-hints --allowed-fixme-codes-strict 2001,2035,2071,4030 --allowed-decl-fixme-codes 2001,2035,2071,4030 --extra-builtin ../hhi/XHPTest.hhi
PHP
hhvm/hphp/hack/test/decl/higher_kinded.php
<?hh // strict type ID<T> = T; type Test1<TC<TA1, TA2<TA3>>> = TC<int, ID>; function filter<TC<_>, TV>(TC<TV> $collection): vec<TV> { return vec[]; }
PHP
hhvm/hphp/hack/test/decl/ifc_policied.php
<?hh <<file:__EnableUnstableFeatures('ifc')>> class Policy {} class C { <<__Policied("Test")>> public function f(): void {} <<__Policied("Public")>> public function g(): void {} <<__Policied>> public function implicit(): void {} <<__InferFlows>> public function inferflows(): void {} <<__Policied(Policy::class)>> public function classname(): void {} // should be default public function defaults(): void {} public function with_args( <<__External>> C $x, <<__CanCall>> (function(): void) $f ): void {} } <<__InferFlows>> function inferflows(): void {}
PHP
hhvm/hphp/hack/test/decl/like_types.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. <<__SupportDynamicType>> function expect_int(int $i): void {} function f<T as ~int>(T $t): void { expect_int($t); } abstract class X { abstract const type T as ~int; public function f(this::T $t): void { expect_int($t); } }
PHP
hhvm/hphp/hack/test/decl/module_attr.php
//// modules.php <?hh <<file:__EnableUnstableFeatures('modules')>> new module here {} new module there {} new module elsewhere {} //// here.php <?hh <<file:__EnableUnstableFeatures('modules')>> module here; function foo():void { } type Talias = int; newtype Topaque = string; //// there.php <?hh <<file:__EnableUnstableFeatures('modules')>> module there; class C { public function bar():void { } } //// elsewhere.php <?hh <<file:__EnableUnstableFeatures('modules')>> module elsewhere; enum E : int { A = 3; }
PHP
hhvm/hphp/hack/test/decl/module_enums.php
//// modules.php <?hh <<file:__EnableUnstableFeatures('modules')>> new module X {} new module Y {} //// X.php <?hh <<file:__EnableUnstableFeatures('modules')>> module X; internal enum X: int { A = 0; B = 1; C = 2; } internal function f1(X $x): void {} // ok function f2(X $x): void {} // error internal function f5(): void { $x = X::A; // ok } function f6(): void { $x = X::A; // ok } //// Y.php <?hh <<file:__EnableUnstableFeatures('modules')>> module Y; function f3(X $x): void {} // error function f7(): void { $x = X::A; // error } //// no-module.php <?hh function f4(X $x): void {} // error function f8(): void { $x = X::A; // error }
PHP
hhvm/hphp/hack/test/decl/module_hint.php
//// modules.php <?hh <<file:__EnableUnstableFeatures('modules')>> new module here {} new module there {} //// here.php <?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. <<file:__EnableUnstableFeatures('modules')>> module here; internal class C { public function bar(mixed $m):void { // All not ok $m as D; $m as G<_>; $m as (D,int); $m is D; $m is G<_>; $m is (D,int); $m as E; $m is E; genfun<D>(null); $x = vec<D>[]; $x = new MyList<D>(); // All ok $m as C; $m is C; } } //// there.php <?hh <<file:__EnableUnstableFeatures('modules')>> module there; internal class D { } internal class G<T> { } internal enum E : int { A = 1; } //// everywhere.php <?hh function genfun<T>(?T $x):?T { return $x; } class MyList<T> { }
PHP
hhvm/hphp/hack/test/decl/module_methods.php
//// modules.php <?hh <<file:__EnableUnstableFeatures('modules')>> new module A {} //// A.php <?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. <<file:__EnableUnstableFeatures('modules')>> module A; class A { internal function f(): void {} } //// main.php <?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. function main(): void { $a = new A(); $a->f(); }
PHP
hhvm/hphp/hack/test/decl/module_properties.php
//// modules.php <?hh <<file:__EnableUnstableFeatures('modules')>> new module A {} //// A.php <?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. <<file:__EnableUnstableFeatures('modules')>> module A; class A { internal int $x = 0; } //// f.php <?hh function f(A $a): void { $a->x = 123; }
PHP
hhvm/hphp/hack/test/decl/module_references.php
<?hh <<file:__EnableUnstableFeatures('modules')>> <<file:__EnableUnstableFeatures('module_references')>> new module a.b { } new module a.c { } new module z.c { } new module a { exports { } imports { } } new module b { exports { } } new module c { imports { } } new module z { imports { a.*, self.c, global, } exports { z.* } }
PHP
hhvm/hphp/hack/test/decl/module_static_prop.php
//// modules.php <?hh <<file:__EnableUnstableFeatures('modules')>> new module A {} new module B {} //// A.php <?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. <<file:__EnableUnstableFeatures('modules')>> module A; class A { internal static int $x = 0; } function a(): void { A::$x = 1; } //// B.php <?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. <<file:__EnableUnstableFeatures('modules')>> module B; function b(): void { A::$x = 1; } //// no-module.php <?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. function none(): void { A::$x = 1; }
PHP
hhvm/hphp/hack/test/decl/multiple_user_attributes_on_class.php
<?hh class Foo implements HH\ClassAttribute {} class Bar implements HH\ClassAttribute {} <<Foo, Bar>> class C {}
PHP
hhvm/hphp/hack/test/decl/namespaces1.php
<?hh namespace { type MyAnonymousNamespaceType = string; class MyClass {} } namespace MyNamespace { type MyNamespaceType = string; class MyClass {} }
PHP
hhvm/hphp/hack/test/decl/namespace_body_plus_declarations_outside_body.php
<?hh namespace X { function a(): void {} } // This is illegal--can't mix namespace declarations with bodies and // declarations outside a namespace body in the same file. function b(): void {}
PHP
hhvm/hphp/hack/test/decl/namespace_elaboration.php
<?hh // The function and const imports don't affect decls, but they're included // because we have to make sure that they don't cause the direct decl parser to // return an error. use \MyNamespace\MyType; use \MyNamespace\MyType as MyType2; use function \MyNamespace\dont_care; use function \MyNamespace\dont_care as really_dont_care; use const \MyNamespace\DONT_CARE; use const \MyNamespace\DONT_CARE as REALLY_DONT_CARE; use \MyNamespace\MyOtherType, \MyNamespace\MyOtherType as MyOtherType2, function \MyNamespace\other_dont_care, function \MyNamespace\other_dont_care as other_really_dont_care, const \MyNamespace\OTHER_DONT_CARE, const \MyNamespace\OTHER_DONT_CARE as OTHER_REALLY_DONT_CARE; use \MyNamespace\{ MyBracedType, MyBracedType as MyBracedType2, function braced_dont_care, function braced_dont_care as braced_really_dont_care, const BRACED_DONT_CARE, const BRACED_DONT_CARE as BRACED_REALLY_DONT_CARE, }; function id(MyType $x): MyType2 { return $x; } function other_id(MyOtherType $x): MyOtherType2 { return $x; } function braced_id(MyBracedType $x): MyBracedType2 { return $x; }
PHP
hhvm/hphp/hack/test/decl/namespace_global_body_plus_declarations_outside_body.php
<?hh namespace { function a(): void {} } // This is illegal--a file containing a global `namespace {}` declaration cannot // have any code outside the namespace body. function b(): void {}
PHP
hhvm/hphp/hack/test/decl/namespace_import.php
<?hh // strict namespace { namespace NS1 { namespace NS2 { type T = int; class C {} } } use NS1\NS2 as NS; function test(): NS\T { return 4; } <<__Sealed(NS\C::class)>> class D {} }
HTML Help Workshop
hhvm/hphp/hack/test/decl/namespace_keyword.hhi
<?hh // partial namespace HH\Rx; interface Traversable<+Tv> extends \HH\Traversable<Tv> {} interface Iterator<+Tv> extends namespace\Traversable<Tv> {}
PHP
hhvm/hphp/hack/test/decl/namespace_self.php
<?hh // strict namespace NS1\NS2; class C { const string KEY = 'KEY'; const type TInt = int; const type TShape = shape( self::KEY => self::TInt, ); public function f(self::TInt $x): void {} }
PHP
hhvm/hphp/hack/test/decl/namespace_use.php
<?hh //strict namespace { namespace NS1 { namespace NS2 { trait MyTrait {} } } use namespace NS1\NS2; final class C { use NS2\MyTrait; } }
PHP
hhvm/hphp/hack/test/decl/namespace_use_kind.php
<?hh // strict use const UseNS\Foo; use type UseNS\Bar; use function UseNS\Baz; use namespace UseNS\NS; type A = Foo; type B = Bar; type C = Baz; type D = NS\Qux;
PHP
hhvm/hphp/hack/test/decl/nested_namespaces.php
<?hh namespace MyNamespace { type MyString = string; type MyInt = int; type MyFloat = float; type MyNum = num; type MyBool = bool; type MyNamespacedType = \MyNamespace\MyString; namespace InnerNamespace { type MyInnerType = string; type MyDoubleNamespacedType = \MyNamespace\MyNamespacedType; } namespace Very\Inner\Namespace { type MyVeryInnerNamespaceType = string; class MyClass {} } type MyVeryInnerNamespaceType = Very\Inner\Namespace\MyVeryInnerNamespaceType; const MyVeryInnerNamespaceType hello = "hello"; }
PHP
hhvm/hphp/hack/test/decl/newtype_super_constraint.php
<?hh <<file:__EnableUnstableFeatures('newtype_super_bounds')>> newtype X as arraykey super string = string; newtype Y super num = mixed;
PHP
hhvm/hphp/hack/test/decl/override_attribute.php
<?hh class B { public function f(): void {} } class C extends B { <<__Override>> public function f(): void {} }
HTML Help Workshop
hhvm/hphp/hack/test/decl/php_std_lib.hhi
<?hh <<__PHPStdLib>> function f(): void {} <<__PHPStdLib>> class C { <<__PHPStdLib>> private ?int $x; <<__PHPStdLib>> private static ?int $y; <<__PHPStdLib>> public function f(): void{} <<__PHPStdLib>> public static function g(): void{} }
PHP
hhvm/hphp/hack/test/decl/property_declarations.php
<?hh class C { private Map<int, int> $map = Map {}, $uninit; public function __construct() { $this->uninit = Map {}; } }
PHP
hhvm/hphp/hack/test/decl/readonly.php
<?hh // strict class Foo { } async function returns_readonly() : readonly Awaitable<Foo> { return new Foo(); } async function returns_normal(): Awaitable<Foo> { return new Foo(); } class Bar { public readonly Foo $x; public function __construct( public readonly Foo $y, ) { $this->x = new Foo(); } public readonly function getFoo((readonly function(): void) $v) : void { $f = /* <<readonly>> */ (Foo $y) ==> {return $y;}; $z = readonly function(Foo $f) : void { }; } }
PHP
hhvm/hphp/hack/test/decl/return_disposable.php
<?hh // strict final class Bar implements IDisposable { public function __dispose(): void {} } <<__ReturnDisposable>> async function gen(): Awaitable<Bar> { return new Bar(); }
PHP
hhvm/hphp/hack/test/decl/return_pos.php
<?hh abstract final class DeclPos<T> { public static function f1()[]: <<__Soft>> varray_or_darray<T> {return darray[];} public static function f2(): <<__Soft>> vec_or_dict<mixed> {return varray[];} public static function f3(): <<__Soft>> darray<int, int> {return darray[];} public static async function genf4(): <<__Soft>> Awaitable<string> {return "a";} public static function f5(): <<__Soft>> bool {return true;} public static function f6()[rx_shallow]: <<__Soft>> string {return "a";} }
PHP
hhvm/hphp/hack/test/decl/ret_from_kind.php
<?hh /* HH_FIXME[4030] */ async function no_hint_async() {} /* HH_FIXME[4030] */ function no_hint_generator() { yield 3; } /* HH_FIXME[4030] */ async function no_hint_async_generator() { yield 3; }
PHP
hhvm/hphp/hack/test/decl/rewritten_tparams.php
<?hh final class P { const ctx C = []; } function f( (function ()[_]: void) $f, P $v )[ctx $f, $v::C]: void { print "hi"; } function g(P $v)[$v::C]: int { return $v; } function h( ?(function ()[_]: void) $f, ?P $v )[ctx $f, $v::C]: void { print "hi"; }
PHP
hhvm/hphp/hack/test/decl/safe_global_variable_attribute.php
<?hh // strict class B { public static int $static_property = 0; <<__SafeForGlobalAccessCheck>> public static int $static_property_safe = 0; } class C { private static int $static_property = 0; <<__SafeForGlobalAccessCheck>> private static int $static_property_safe = 0; public string $instanceProperty = ""; public function foo(): void { self::$static_property = 1; self::$static_property_safe = 1; B::$static_property = 1; B::$static_property_safe = 1; } }
PHP
hhvm/hphp/hack/test/decl/self_in_type_constant.php
<?hh class C { const type T = int; const type U = self::T; } interface I { const type V = int; const type W = self::V; } trait T { require extends C; abstract public function f(): self::U; }
PHP
hhvm/hphp/hack/test/decl/shapes.php
<?hh type Coordinate = shape('x' => float, 'y' => float, ...); function takes_shape(shape('x' => float, 'y' => float) $arg1): Coordinate { return $arg1; } function returns_shape( Coordinate $arg1, ): shape('x' => float, 'y' => float, ...) { return $arg1; } function generic_shape<T>((T, T) $arg1): (T, T) { return $arg1; } type TaggedCoordinate = shape(?'tag' => string, 'coord' => shape('x' => float, 'y' => float));
PHP
hhvm/hphp/hack/test/decl/shape_expression_key_types.php
<?hh class C { const string KEY = 'KEY'; const mixed X = shape( 0 => 0, 's' => 's', C::class => C::class, C::KEY => C::KEY, ); }
PHP
hhvm/hphp/hack/test/decl/shape_self.php
<?hh // strict class TestClass { const string KEY = 'key'; const type TClassType = shape( self::KEY => int, ); }
PHP
hhvm/hphp/hack/test/decl/shape_type_key_types.php
<?hh type Shape = shape( 0 => int, 's' => string, C::class => classname<C>, C::KEY => string, );
PHP
hhvm/hphp/hack/test/decl/sound_dynamic_call_meth_1.bad.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. <<__SupportDynamicType>> class A<T> {} class C { <<__SupportDynamicType>> public function expect_A_int(A<int> $a1, A<int> $a2) : void {} } // handling of Sound Dynamic Callable methods defined in other classes // is not complete; this should ideally be accepted, but it is not <<__SupportDynamicType>> class Foo { public function foo(A<int> $a) : void { (new C())->expect_A_int($a, new A<int>()); } public function bar(A<int> $a) : void { (new C())->expect_A_int(new A<int>(), $a); } }
PHP
hhvm/hphp/hack/test/decl/static_method_call_with_explicit_targ.php
<?hh // strict class C { public static function f(): int { if (static::equal<int>(0, 0)) { return 1; } return 0; } public static function equal<T>(T $a, T $b): bool { return $a === $b; } }
PHP
hhvm/hphp/hack/test/decl/tparams_on_class_and_method.php
<?hh // strict class C<Ta, Tb> { public function f<Tc>(Ta $a, Tc $c): (Ta, Tc) { return tuple($a, $c); } public function g<Td>(Tb $b, Td $d): (Tb, Td) { return tuple($b, $d); } }
PHP
hhvm/hphp/hack/test/decl/traits.php
<?hh trait TMyTrait { public function doNothing(): void {} } trait TMyTrait2 { use TMyTrait; public function doMoreNothing(): void {} } trait TMyTrait3 { public function doYetMoreNothing(): void {} } class MyTraitUsingClass { use TMyTrait2; use TMyTrait3; }
PHP
hhvm/hphp/hack/test/decl/trait_require_class.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. <<file:__EnableUnstableFeatures('require_class')>> trait T1 { require class C; } trait T2 { require class C; require class D; } class C {} class D {}
PHP
hhvm/hphp/hack/test/decl/tuples.php
<?hh type Coordinate = (float, float); function takes_tuple((float, float) $arg1): Coordinate { return $arg1; } function returns_tuple(Coordinate $arg1): (float, float) { return $arg1; } function generic_tuple<T>((T, T) $arg1): (T, T) { return $arg1; }
PHP
hhvm/hphp/hack/test/decl/typeconst_property_promotion.php
<?hh class C { const type T = int; public function __construct( private this::T $a, ): void { } } // Using `this::T` with parameter promotion requires the decl parser to clone // the representation of `this::T` between the property and the parameter. // Because we use internal mutability in the TypeconstAccess node, it is // tempting to use `RefCell::replace` to take the contents of our typeconst // names Vec when converting to a type, but it is incorrect to do so because of // this clone.
PHP
hhvm/hphp/hack/test/decl/typedefs.php
<?hh // We expect some typechecker errors in this one because we want the decl parser // to be more accepting than the typechecker. namespace MyNamespace { type MyString = string; } type MyArray = varray_or_darray; type MyArray1<T> = varray<T>; type MyArray2<TK, TV> = darray<TK, TV>; type MyDarray<TK, TV> = darray<TK, TV>; type MyVarray<T> = varray<T>; type MyVarrayOrDarray<TK, TV> = varray_or_darray<TK, TV>; type MyString = string; type MyInt = int; type MyFloat = float; type MyNum = num; type MyBool = bool; type MyMixed = mixed; type MyNothing = nothing; type MyNonnull = nonnull; type MyDynamic = dynamic; type MyArrayKey = arraykey; type MyNamespacedType = \MyNamespace\MyString; newtype MyNewtype as num = int; newtype MyNewtypeWithoutConstraint = int;
PHP
hhvm/hphp/hack/test/decl/type_param_attrs.php
<?hh // strict class A implements HH\TypeParameterAttribute { public function __construct() {} } class C<<<__Enforceable, A>> reify T1> {}
PHP
hhvm/hphp/hack/test/decl/unnamed_variadic_method_parameter.php
<?hh // strict class C { public function f(int $foo, ...): void { throw new Exception(); } }
PHP
hhvm/hphp/hack/test/decl/untyped_prop.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ class Y { /* HH_FIXME[2001] */ public $x = false; }
PHP
hhvm/hphp/hack/test/decl/user_attributes_in_namespaces.php
<?hh namespace X { class Foo implements \HH\ClassAttribute {} namespace Y { class Bar implements \HH\ClassAttribute {} } <<Foo, Y\Bar>> class C {} }
PHP
hhvm/hphp/hack/test/decl/use_type.php
<?hh // strict namespace { namespace NS { class C {} } namespace C { class X {} } use type NS\C; class D extends C {} function f(C\X $x): void {} }
PHP
hhvm/hphp/hack/test/decl/wildcard_invalid.php
<?hh // strict function foo(_ $x): void { } function bar(mixed $x): _ { } final class C { public function __construct(private _ $foo) {} }
PHP
hhvm/hphp/hack/test/decl/wildcard_invalid_targ.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class C<reify Tc> {} class D extends C<_> {} class E extends C<C<_>> {} function test(C<C<_>> $c): C<_> { return $c; }
PHP
hhvm/hphp/hack/test/decl/xhp.php
<?hh // strict class xhp {} class :foo {} class :foo:bar {} class :foo-baz {} function xhp_is_valid_class_name(xhp $x): void {}
PHP
hhvm/hphp/hack/test/decl/xhp_attr.php
<?hh // strict class :bar {} class :foo { public ?string $before; attribute int a = 0; attribute int b; attribute int c @required; attribute ?int d = null; attribute enum {'a', 'b'} e; attribute int f @lateinit; attribute mixed g; attribute :bar; public ?string $after; }
PHP
hhvm/hphp/hack/test/decl/xhp_self.php
<?hh // strict type REACT_XHP_FIX<+T> = T; final class :Foo extends XHPTest { const type TProps = shape("x" => int); attribute REACT_XHP_FIX<self::TProps> props @required; protected function getProps(): self::TProps { return $this->:props; } }
PHP
hhvm/hphp/hack/test/decl/yield_deeper.php
<?hh // strict function f(): Generator<bool, string, int> { $x = yield true => 'a'; } function g(): void { $x = async function() { yield 0; }; } function h(): void { $x = () ==> { yield 0; }; } async function i(): Awaitable<void> { await async { yield 0; yield 1; }; } async function j(): AsyncKeyedIterator<string, int> { if (true) { yield 'a' => 1; } else { yield 'b' => 2; } if (false) { yield 'c' => 3; } else { yield 'd' => 4; } }
Rust
hhvm/hphp/hack/test/decl/serialize/main.rs
// Copyright (c) Facebook, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. use std::fs::File; use std::io::Read; use std::path::Path; use std::path::PathBuf; use ::anyhow::Context; use ::anyhow::Result; use clap::Parser; use oxidized_by_ref::direct_decl_parser::Decls; use relative_path::RelativePath; use serde::Deserialize; use serde::Serialize; use walkdir::WalkDir; #[derive(Parser, Clone, Debug)] pub struct Opts { path: PathBuf, } fn main() -> ::anyhow::Result<()> { let opts = Opts::try_parse()?; let mut path = std::env::current_dir().expect("current path is none"); path.push(opts.path); let mut results: Vec<Result<Profile, Error>> = vec![]; for f in WalkDir::new(path).into_iter().filter(|e| { e.as_ref() .expect("expect file path") .path() .extension() .map_or(false, |e| e == "php") }) { let entry = f?; let path = entry.path(); let content = read_file(path)?; let relative_path = RelativePath::make(relative_path::Prefix::Dummy, path.to_path_buf()); let arena = bumpalo::Bump::new(); let parsed_file = direct_decl_parser::parse_decls_for_typechecking( &Default::default(), relative_path, &content, &arena, ); let decls = parsed_file.decls; results.push(round_trip::<Decls<'_>, Json>(&arena, path, decls)); results.push(round_trip::<Decls<'_>, FlexBuffer>(&arena, path, decls)); results.push(round_trip::<Decls<'_>, Bincode>(&arena, path, decls)); results.push(round_trip::<Decls<'_>, Cbor>(&arena, path, decls)); } let (profiles, errs) = results .into_iter() .fold((vec![], vec![]), |(mut pr, mut er), r| { match r { Ok(p) => pr.push(p), Err(e) => er.push(e), }; (pr, er) }); if !errs.is_empty() { errs.iter().for_each(|e| println!("Faild: {:#?}", e)); panic!("mismatch") } use std::collections::HashMap; let aggrate_by_provider = profiles.into_iter().fold(HashMap::new(), |mut m, p| { if m.get(p.provider).is_none() { m.insert( p.provider, Profile { provider: p.provider, filepath: PathBuf::new(), se_in_ns: 0, de_in_ns: 0, data_size_in_bytes: 0, }, ); } else { let agg = m.get_mut(p.provider).unwrap(); agg.se_in_ns += p.se_in_ns; agg.de_in_ns += p.de_in_ns; agg.data_size_in_bytes += p.data_size_in_bytes; } m }); println!("Profiling data: {:#?}\n", aggrate_by_provider); Ok(()) } fn read_file(filepath: &Path) -> Result<Vec<u8>> { let mut text: Vec<u8> = Vec::new(); File::open(filepath) .with_context(|| format!("cannot open input file: {}", filepath.display()))? .read_to_end(&mut text)?; Ok(text) } fn round_trip<'a, X, P: Provider>( arena: &'a bumpalo::Bump, filepath: &Path, x: X, ) -> Result<Profile, Error> where X: Deserialize<'a> + Serialize + Eq + std::fmt::Debug, P: Provider, { use std::time::SystemTime; let provider = P::name(); let mk_err = |msg| Error { provider, filepath: filepath.into(), msg, }; let s = SystemTime::now(); let data = P::se(&x).map_err(mk_err)?; let se_in_ns = SystemTime::now().duration_since(s).unwrap().as_nanos(); let data_size_in_bytes = P::get_bytes(&data).len(); let s = SystemTime::now(); let y = P::de(&arena, data).map_err(mk_err)?; let de_in_ns = SystemTime::now().duration_since(s).unwrap().as_nanos(); if x == y { Ok(Profile { provider: P::name(), filepath: filepath.into(), se_in_ns, de_in_ns, data_size_in_bytes, }) } else { Err(mk_err("not equal".into())) } } #[derive(Debug)] struct Profile { provider: &'static str, #[allow(dead_code)] filepath: PathBuf, se_in_ns: u128, de_in_ns: u128, data_size_in_bytes: usize, } #[derive(Debug)] struct Error { #[allow(dead_code)] provider: &'static str, #[allow(dead_code)] filepath: PathBuf, #[allow(dead_code)] msg: String, } trait Provider { type Data; fn se<X: serde::Serialize>(x: &X) -> Result<Self::Data, String>; fn de<'a, X: serde::Deserialize<'a>>( arena: &'a bumpalo::Bump, data: Self::Data, ) -> Result<X, String>; fn name() -> &'static str; fn get_bytes(data: &Self::Data) -> &[u8]; } struct Json; impl Provider for Json { type Data = String; fn name() -> &'static str { "serde_json" } fn se<X: serde::Serialize>(x: &X) -> Result<Self::Data, String> { serde_json::to_string(x) .map_err(|e| format!("{} failed to serialize, error: {}", Self::name(), e)) } fn de<'a, X: serde::Deserialize<'a>>( arena: &'a bumpalo::Bump, data: Self::Data, ) -> Result<X, String> { let mut de = serde_json::Deserializer::from_str(&data); let de = arena_deserializer::ArenaDeserializer::new(arena, &mut de); X::deserialize(de) .map_err(|e| format!("{} failed to deserialize, error: {}", Self::name(), e)) } fn get_bytes(data: &Self::Data) -> &[u8] { data.as_bytes() } } struct FlexBuffer; impl Provider for FlexBuffer { type Data = flexbuffers::FlexbufferSerializer; fn name() -> &'static str { "flexbuffers" } fn se<X: serde::Serialize>(x: &X) -> Result<Self::Data, String> { let mut s = flexbuffers::FlexbufferSerializer::new(); x.serialize(&mut s) .map_err(|e| format!("{} failed to serialize, error: {}", Self::name(), e))?; Ok(s) } fn de<'a, X: serde::Deserialize<'a>>( arena: &'a bumpalo::Bump, data: Self::Data, ) -> Result<X, String> { let de = flexbuffers::Reader::get_root(data.view()).map_err(|e| { format!( "{} failed to create deserializer, message {}", Self::name(), e ) })?; let de = arena_deserializer::ArenaDeserializer::new(arena, de); X::deserialize(de) .map_err(|e| format!("{} failed to deserialize, error: {}", Self::name(), e)) } fn get_bytes(data: &Self::Data) -> &[u8] { data.view() } } struct Bincode; impl Provider for Bincode { type Data = Vec<u8>; fn name() -> &'static str { "bincode" } fn se<X: serde::Serialize>(x: &X) -> Result<Self::Data, String> { use bincode::Options; let op = bincode::config::Options::with_native_endian(bincode::options()); op.serialize(x) .map_err(|e| format!("{} failed to serialize, error: {}", Self::name(), e)) } fn de<'a, X: serde::Deserialize<'a>>( arena: &'a bumpalo::Bump, data: Self::Data, ) -> Result<X, String> { let op = bincode::config::Options::with_native_endian(bincode::options()); let mut de = bincode::de::Deserializer::from_slice(&data, op); let de = arena_deserializer::ArenaDeserializer::new(arena, &mut de); X::deserialize(de) .map_err(|e| format!("{} failed to deserialize, error: {}", Self::name(), e)) } fn get_bytes(data: &Self::Data) -> &[u8] { data.as_slice() } } struct Cbor; impl Provider for Cbor { type Data = Vec<u8>; fn name() -> &'static str { "cbor" } fn se<X: serde::Serialize>(x: &X) -> Result<Self::Data, String> { let mut data = vec![]; serde_cbor::to_writer(&mut data, x) .map_err(|e| format!("{} failed to deserialize, error: {}", Self::name(), e))?; Ok(data) } fn de<'a, X: serde::Deserialize<'a>>( arena: &'a bumpalo::Bump, data: Self::Data, ) -> Result<X, String> { let mut de = serde_cbor::de::Deserializer::from_reader(data.as_slice()); let de = arena_deserializer::ArenaDeserializer::new(arena, &mut de); X::deserialize(de) .map_err(|e| format!("{} failed to deserialize, error: {}", Self::name(), e)) } fn get_bytes(data: &Self::Data) -> &[u8] { data.as_slice() } }
hhvm/hphp/hack/test/decl/with_attributes/HH_FLAGS
--auto-namespace-map '{"Dict":"HH\\Lib\\Dict"}' --enable-xhp-class-modifier --like-type-hints --allowed-fixme-codes-strict 2001,2035,2071,4030 --allowed-decl-fixme-codes 2001,2035,2071,4030 --keep-user-attributes
PHP
hhvm/hphp/hack/test/decl/with_attributes/user_attributes_params.php
<?hh class C { <<Foo("hi " . "there")>> public function attrStr() {} <<Foo(0x42, 123)>> public function attrInt(); <<Foo(SomeClass#Label1, #Label2)>> public function attrECLabel() {} <<Foo(SomeClass::class)>> public function attrClsName() {} <<Foo(21 * 2)>> public function attrCompute() {} }
PHP
hhvm/hphp/hack/test/deps/circular_type_method_deps.php
<?hh class C implements Compare { public function eq(C $c_obj): bool { $c_obj->content(); return True; } public function content(): void { } } interface Compare { public function eq(C $c_obj): bool; }
hhvm/hphp/hack/test/deps/dune
(rule (alias deps) (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/deps/*.php) (glob_files %{project_root}/hack/test/deps/*.exp) (glob_files %{project_root}/hack/test/deps/HH_FLAGS)) (action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/deps --program %{exe:../../src/hh_single_type_check.exe}))) (alias (name runtest) (deps (alias deps)))
PHP
hhvm/hphp/hack/test/deps/invoking_funs.php
<?hh type C = int; function A()[read_globals] : int { return 0; } function B()[globals] : C { return A(); }
PHP
hhvm/hphp/hack/test/deps/namespaces.php
<?hh namespace N { class Foo {} class Bar extends Foo {} } namespace { class Foo {} class Bar extends Foo {} class Baz extends Bar {} class Qux extends N\Foo {} }
PHP
hhvm/hphp/hack/test/deps/namespaces_consts.php
//// file1.php <?hh const C = 1; //// file2.php <?hh namespace NS { const C = 'a'; function bar()[]: int { return C; } }
PHP
hhvm/hphp/hack/test/deps/namespaces_funs.php
//// file1.php <?hh function foo()[]: string { return ''; } namespace NS { function foo()[]: int { return 0; } } //// file2.php <?hh namespace NS { function bar()[]: int { return foo(); } }