language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
PHP
hhvm/hphp/hack/test/full_fidelity/cases/parameter_promotion.php
<?hh // strict class GoodExample { public function __construct(public int $p) {} } class AlsoGoodBecauseNotOverlapping { public int $p; public function __construct(int $p, public int $q) { $this->p = $p; } } class DuplicateDeclarations { public int $p; public function __construct(public int $p) {} } trait PromoInTrait { public function __construct(public int $p) {} } interface PromoInInterface { public function __construct(public int $p); } abstract class PromoInAbstractConstruct { public abstract function __construct(public int $p) {} } class PromoInMethod { public function foo(public int $p): void {} }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/readonly_return_without_type.php
<?hh // partial class Foo { public int $prop = 44; public function foo() : readonly { $x = function (): readonly {}; $f = function (): readonly use ($x) {}; $f = () : readonly ==> {}; $g = () : readonly int ==> { return 5; }; return 5; } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/reassign_this.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 X { public function f($x): void { $this = $x; } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/reassign_this2.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 X { public function f($x): void { list($_, $this, $y) = $x; } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/scope_resolution_expression_lval.php
<?hh function foo(): void { Foo::$bar = 1; // OK Foo::{$bar} = 2; // OK Foo::BAR = 3; // Not OK }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_abstract_classish_errors.php
<?hh // strict interface I1 { // legal } abstract interface I1 { // errror2042 } class C1 { // legal } abstract class C2 { // legal } trait T { // legal } abstract trait T { // error2043 }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_abstract_final_errors.php
<?hh //strict abstract final class AbstractFinalClassWithWrongProperty { public int $x; } abstract final class AbstractFinalClassWithRightProperty { public static int $x; } abstract final class AbstractFinalClassWithWrongMethod { public function x(): void {} } abstract final class AbstractFinalClassWithRightMethod { public static function x(): void {} }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_abstract_initializers.php
<?hh //strict class ConcreteRight { const int i1 = 4; } class ConcreteWrong { const int i1; } abstract class AbstractRight { abstract const int i1; } abstract class AbstractWrong { abstract const int i1 = 3; } abstract class MixedRight { const int i1 = 5; } abstract class MixedWrong { const int i1; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_abstract_methodish_errors.php
<?hh // strict interface I1 { public function i1(): void; // legal public abstract function i2(): void; // error2045 } class C1 { // technically is half of errror2044, but we report error2044 later public function c2(): void { } // legal public abstract function c3(): void; // error2044 reported here } abstract class C2 { // legal public function c1(): void { } // legal public abstract function c2(): void; // legal } trait T { public function t1(): void { } // legal public abstract function t2(): void; // legal }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_alias_errors.php
<?hh //strict type foo as bar = blah; // error newtype foo2 as bar2 = blah2; // legal type foo3 = blah3; // legal
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_async_errors.php
<?hh // strict interface I { public function i1(): void; // legal public async function i2(): Awaitable<void>; // error2046 } abstract class C { public function c1(): void { } // legal public async function c2(): Awaitable<void> { } // legal public abstract async function c3(): Awaitable<void>; // error2046 } trait T { public function t1(): void { } // legal public async function t2(): Awaitable<void> { } // legal public abstract async function t3(): Awaitable<void>; // error2046 }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_as_expression_errors.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. * * */ function test(mixed $e): void { $e as @int; // error }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_awaitable_creation.php
<?hh function f () { $a = async {}; $a = async {} + 1; $a = 1 + async {}; $a = async {} + async {}; $a = async { $a = 1; }; $a = async { $b = async {} + 1; }; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_classish_inside_function_errors.php
<?hh function earlier(){ function later(){ class BadClass{ // error2039 } interface BadInterface{ // error2039 } trait BadTrait{ // error2039 } } } class ThisIsFine{ // legal } interface ThisIsFine{ // legal } trait ThisIsFine{ // legal } class C { public function foo() { class D {} // error2039 triggered from inside methods too } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_class_const.php
<?hh // strict class MyClassName { const WHITE = "white"; const string TRUE = "true"; const Serializable<string> BLUE = "blue\u{0123}"; public const string PublicConst = "this should fail"; protected const string ProtectedConst = "this should fail"; private const string PrivateConst = "this should fail"; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_class_const_phpmode.php
<?hh class MyClassName { const WHITE = "white"; const string TRUE = "true"; const Serializable<string> BLUE = "blue\u{0123}"; public const string PublicConst = "this is fine in PHP mode"; protected const string ProtectedConst = "this is fine in PHP mode"; private const string PrivateConst = "this is fine in PHP mode"; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_class_level_where_constraint.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 A <T> where T as num {}
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_class_level_where_constraint_list.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 A <T> where T as num T as string {}
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_class_level_where_constraint_multiple_generics.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 A <T, Tu> where T as num T as string, Tu as num {}
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_class_method_declaration.php
<?hh class C { public static function f () : void {} public abstract function g () ; <<attr>> public function h () {} <<attr>> public static function ff () : void {} }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_class_type_const.php
<?hh abstract class MyClassName { public abstract const type T1; protected abstract const type T2; private abstract const type T3; public const type T4 = int; protected const type T5 = int; private const type T6 = int; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_closure_type.php
<?hh // strict function foo ((function (int) : int) $f) : int { $x = $f(0); return $x; } function bar ((function (...) : int) $f) : int { return $f(1, 2, 3); } function baz ((function (inout string, int) : void) $f) : string { $y = 'zzz'; $f(inout $y, 42); return $y; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_constructor_destructor.php
<?hh class C { private function __construct($a) {} public function __construct($a = null) {} public function __construct($a) {} private function __construct($a = null) {} <<attr>> public function __construct ($a){} <<attr>> public function __construct ($a) {} public function __construct (public $a = null) {} }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_correct_code1.php
<?hh // This is an anonymized excerpt of a file from www. // It's syntactically correct and should therefore parse without error. // It's being included in the full_fidelity tests simply to increase coverage. type T = shape( C::PROPERTY1 => string, C::PROPERTY2 => int, C::PROPERTY3 => int, C::PROPERTY4 => string, C::PROPERTY5 => int, C::PROPERTY6 => ?int, C::PROPERTY7 => ?string, C::PROPERTY8 => ?Set<int>, C::PROPERTY9 => ?Set<string>, C::PROPERTY10 => ?Set<string>, C::PROPERTY11 => ?int, ); abstract final class C{ const string PROPERTY1 = 'property1'; const string PROPERTY2 = 'property2'; const string PROPERTY3 = 'property3'; const string PROPERTY4 = 'property4'; const string PROPERTY5 = 'property5'; const string PROPERTY6 = 'property6'; const string PROPERTY7 = 'property7'; const string PROPERTY8 = 'property8'; const string PROPERTY9 = 'property9'; const string PROPERTY10 = 'property10'; const string PROPERTY11 = 'property11'; public static async function propertyID( string $id, string $type, ): Awaitable<?ID_of<Property>> { $intermediate_id = 0; switch ($type) { case self::PROPERTY1: $intermediate_id = await (new Something())->genOne($id); break; case self::PROPERTY2: // Comment $info = await Something::at()->gen($id); // country code needs to be upper cased for whatever reason $result1 = Str\uppercase((string)idx($info, SomeConst::PROPERTY)); $result2 = idx($info, 'code'); $intermediate_id = await (new Something())->genOne($var . ':' . $result2); break; case self::PROPERTY3: // Comment (TODO) // Comment comment comment // Comment $result2 = Str\pad_left($result2, 2, "0"); $intermediate_id = await (new Something())->genOne('STRING:'.$id); break; case self::PROPERTY4: $intermediate_id = await (new Something())->genOne($id); break; case self::PROPERTY5: // Comment comment // Comment if (preg_match('/^\d+$/', $id) == 1) { $id = 'STRING:'.$id; } $intermediate_id = await (new Something())->genOne($id); break; default: FBLogger('Something')->warn('Warning', $type); } $intermediate_id = maybe_oid($intermediate_id); if ($intermediate_id === null) { return null; } // TODO: Something $result4 = await Something::genSomething(); /* comment */ $result5 = await Something::genSomething($input1, $input2); $result6 = await $result4->genID(); return maybe_oid($result6); } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_declaration_errors.php
<?hh interface I { } class B { } class D extends B { require extends B; // error require implements I; // error } interface I2 { require extends B; // no error require implements I; // error } trait T { require extends B; // no error require implements I; // no error }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_default_param_errors.php
<?hh function foo(int $bar = 1, $blah) : void { } class C { public function foo(int $bar = 1, $blah, $baz) : void { } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_errors_array_type.php
<?hh // strict function f (int $a) : Vector<array> {} // error function f (array $a) : int {} // error function f (int $a) : array {} // error function f (array<int> $a) : array<int, string> {} //no error
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_errors_class.php
<?hh final abstract class C {} // no error abstract final class C {} // no error final class C {} // no error abstract class C {} // no error class C {} // no error final final class C {} // error abstract abstract class C {} // error abstract final abstract class C {} // error
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_errors_dynamic_method_call.php
<?hh class C { public function f<T>() {} } class D { public static function f<T>() {} } $x = 'f'; $c = new C(); $c->f<int>(); // ok $c->$x<int>(); // parse error $c?->f<int>(); // ok $c?->$x<int>(); // parse errors D::f<int>(); // ok D::$x<int>(); // parse error
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_errors_method.php
<?hh // strict class E { public private function f () : void {} final final function f () : void {} public abstract final function f () : void ; private abstract function f () : void ; public abstract static function f () : void {} public abstract static function f () : void ; public function f () : void ; public static function __construct () {} public function __construct (public int $k) {} public abstract function __construct () ; public abstract function __construct () {} public function f (public int $k) : void {} public function __construct () : int {} public function __construct () : void {} public function f (...) : void {} // no errors public function f (...,) : void {} // error; trailing comma illegal public function f (..., int $x) : void {} // error; ... must be at end }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_errors_not_strict.php
<?hh function foo($a) { return $a; } function bar() : void { // No error; the annotations are not required on anonymous functions. $x = function($b) { }; $y = <foo:bar:blah baz-abc="123"/>; // no error on well-formed XHP } class C { public $x = 123; // no error; type annotation is optional public int $y = 456; // no error }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_errors_strict.php
<?hh // strict function foo($a) { // two errors; missing annotation on $a and foo. return $a; } function bar() : void { // No error; the annotations are not required on anonymous functions. $x = function($b) { }; $y = <foo:bar:blah baz-abc="123"/>; // no error on well-formed XHP } class C { public $x = 123; // error; type annotation is not optional in strict mode public int $y = 456; // no error }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_errors_variadic_param.php
<?hh function f (...$a) : int {} // no error function f (...$a, $b) : int {} // ERROR function f ($a, ...$b) : int {} // no error function f ($a, ...$b, $c) : int {} // ERROR f ($a, ...$b); //no error f (...$a); // no error f (...$a, $b); // ERROR f ($a, ...$b, $c); // ERROR f ($a, ...$b, ); // no error
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_errors_variadic_param_default.php
<?hh function f (...$a = null) : int {} // ERROR function f ($a, ...$b = null) : int {} // ERROR function f ($a = null, ...$b) : int {} // no error
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_expression_errors.php
<?hh function f($x) { return $x{123}; // error: deprecated subscript syntax } function g($a, $b) { return $a ? : $b; // error: expected elvis operator }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_expression_trees.php
<?hh <<file:__EnableUnstableFeatures('expression_trees')>> function test():void { code`4 + 10 + $x`; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_extends_errors.php
<?hh // strict // legal interface c extends a, b { } // error class c extends a, b { } // error trait c extends a, b { } // legal interface c extends a { } // legal class c extends a { } // error trait c extends a { } // error 1007 interface c extends { } // error 1007 class c extends { } // errors 1007 and 2036 trait c extends { }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_foreach_statements.php
<?hh function f() { foreach ($arr as $v){ } foreach ($arr as $k => $v){ $k++; } foreach ($arr await as $v){ } foreach ($arr await as $k => $v){ } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_for_statements.php
<?hh function foo() { for($x;$y;$z) { return $a; } for($x;$y;$z) {} for(;$y;$z) {} for($x;;$z) {} for($x;$y;) {} for($x;;) {} for(;$y;) {} for(;;$z) {} for($x, $y;;) {} }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_funcall_with_type_arguments.php
<?hh // strict // ficticious functions with size-discernable names f('hi'); // normal function call w/o generics fo<string>('hello'); // annotated function call foo(0 < 0, tuple()); // not generics annotated, but seems so a little fooo(Bar < 0, 10 > Qux); // certainly not annotated, but hard to tell foooo(bar<int,string>()); // annotated inside an argument list 42 * ba<string>('hello'); $x ?? foo<bar>(); 42 * foo<bar>(); 42 * foo<bar>($x); 42 * foo<bar>($x, $y); 42 * x::foo<bar>(); 42 * x::foo<bar>($x); 42 * x::foo<bar>($x, $y); baz(foo<baz>()); baz(foo<baz>($x)); baz(foo<baz>($x, $y)); foo<bar<baz>(); 42 * foo < 90; 42 * foo < 90 + 50; 42 * foo < 90 === true; $f === foo<bar>() ? 1 : 2; foo<bar>($f === foo<bar>() ? 1 : 2); $f === x::foo<bar>(1) ? 1 : 2; x::foo<bar>($f === x::foo<bar>(1) ? 1 : 2); $f === Vector<int>{1,2,3} ? foo<bar>() : x::foo<bar>();
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_global_constant.php
<?hh // strict const A = 10; const A; const int A; const int A = 10; namespace V { const A = 10; const A; const int A; const int A = 10; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_group_use_errors.php
<?hh //strict namespace foo { class C { } class D { } } namespace illegal1 { use \foo { C, D }; } namespace illegal2 { use \foo\ { type C, D }; } namespace illegal3 { use \foo\ { type C, type D }; } namespace legal1 { use \foo\ { C, D }; } namespace legal2 { use \foo; } namespace illegal4 { use \foo as false; } namespace legal3 { use type \foo\C, \foo\D; } namespace legal4 { use type \foo\ { C, D }; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_implements_errors.php
<?hh //strict class Bar1 implements Foo1 { } interface Bar2 implements Foo1 { } trait Bar3 implements Foo1 { } class Bar1 { } interface Bar2 { } trait Bar3 { }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_inclusion_directive.php
<?hh namespace N { include 's'; include_once 'd'; require 's'; require_once 'd'; include ('s'); include_once ('d'); require ('s'); require_once ('d'); }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_incomplete_file.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. interface A { function f<T>() where T
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_inout_params.php
<?hh // strict function noop<T>(inout T $_): void {} function add1(inout int $x): void { $x += 1; } function swap<T>(inout T $a, inout T $b): void { $tmp = $a; $a = $b; $b = $tmp; } function extend<T>(inout vec<T> $dst, Traversable<T> $src): bool { if (!$src) { return false; } foreach ($src as $e) { $dst[] = $e; } return true; } function herp( (function(inout vec<int>, Container<int>): mixed) $f, inout vec<int> $dst, ): void { $f(inout $dst, keyset[5]); } function long_function_name_with_lots_of_args( int $a, string $b, inout arraykey $c, inout dict<int, vec<string>> $d, inout bool $e, int ...$f ): bool { return true; } function test(): void { $i = 42; $s = 'foo'; $b = true; noop(inout $i); add1(inout $i); swap(inout $i, inout $s); $v = vec[]; extend(inout $v, vec[0, 1, 2]); herp(extend<>, inout $v); $d = dict['derp' => dict[6 => vec['burp']]]; $derp = () ==> 'derp'; long_function_name_with_lots_of_args( 42, 'whatever', inout $i, inout $d[$derp()], inout $b, $v[0], ...$v ); }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_inout_params_errors.php
<?hh // strict function f(int $x, inout mixed ...$ys): void {} // ERROR function g1(inout string $s = 'g1'): void {} // ERROR function g2(string $s = 'g2', inout int $i): void {} // ERROR function g3(inout int $i, string $s = 'g3'): void {} // no error function q(inout $x): void {} // ERROR function v((function(inout mixed ...): void) $f): void {} // ERROR function z(inout vec<int> $v): void { $v[] = 42; } // no error class C { public static function x((function(): bool) $p, inout ?C $c): void { if ($p()) { $c = new self(); } } // no error } function test(): void { $i = 999; g3(inout $i, 'ok'); // no error $v = vec[]; $c = async function(inout $v) {}; // ERROR $c = async (inout $v) ==> 42; // ERROR } async function gen_test(): void { $c = function(inout $f) {}; // no error $c = (inout $v) ==> 42; // no error }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_interface_method_errors.php
<?hh // strict interface I { function i1(): int; // legal function i2(): int { } // error2041 } class C { function c1(): void; // error2015 function c2(): void { } // legal } trait T { function t1() : void; // error2015 function t2() : void { } // legal }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_is_expression_errors.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. * * */ function test(mixed $e): void { $e is @int; // error }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_lambda_byref_assign.php
<?hh // strict $f = &() ==> { $x = 5; return $x; }; // error $x = &$foo->bar?->baz; // error $f = &$x; // error $f = &my_func(); // error $f = &$x->member; // error $f = &$x->method(); // error $f = &$xs[$x]; // error $f = &${name}; // error $f = &self::$mySelfThing; // error $f = &$$s; // error $f = &new C(); // error $y = &$$$$$$x; // error $x = &($foo->bar()); // error $x = &(Arrays::slice(self::NORMALIZED_REQUIRED_COLUMN_NAMES, 0)); // error $x = &(PHP\array_slice($app_alerts_array, -1)); // error
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_lambda_no_typehints_errors.php
<?hh //strict /* There should be no errors due to the absence of typehints on $a and $b */ function test():void { $lambda = ($a, $b) ==> { return 1; }; bar(($a, $b) ==> { return 1; }); }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_lambda_variadic_errors.php
<?hh foo((...$x, $y) ==> {}); foo((int ...$x, int $y) ==> {}); foo((..., $y) ==> {}); foo((int ...$x,) ==> {}); foo(function (int ...$x, int $y): void {}); foo(function (...$x, int $y): void {}); foo(function (..., int $y): void {}); foo((inout int ...$x) ==> {}); foo(function (inout int ...$x): void {});
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_legal_php.php
<?hh function f($foo = 1, $bar) { // missing value is illegal in hack, legal in php $a[] = new E; // error2038 in hack, but legal in php }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_like_types.php
<?hh function f( ~int $a, vec<~dict<int, string>> $b, ~SomeClass::TFoo $c, (function(~int): void) $d, ?~int $e, ~?int $f, ~~int $g, (int, ~string) $h, ): void {}
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_list_expression.php
<?hh function f(Bar $vector){ list($a, $b) = $vector; list($a, list($b, $c)) = $vector; list(,,$a,,) = $vector; // Missing binders should be `$_`-style ignores. }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_list_expression_errors.php
<?hh // strict // legal because 'list' can be the value clause of a foreach foreach($array as list($odd, $even)){ } // legal because 'list' can be the operand to a list destructuring list($a, list($b, $c)) = $vector; // legal because nested destructuring, and use as value clause, are both legal foreach($array as list($odd, list($even))){ } // legal because used as left side of simple assignment list($a) = $vector; list(,,$a,,) = $vector; // legal because simple assignment is right-associative $x = list($whatever) = $whatever; foo(list($a, $b)); // error 2040 list(2) + 3; // error 2040 list(2) % 3; // error 2040 function foo(): (int, int) { return list(1, 2); // error, list can only be used as an lvar }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_method_modifier_errors.php
<?hh class A { function a1() {} //error2054 static function a2() {} protected static function a3() {} } interface B { function b1(); //error2054 final function b2(); public final function b3(); } trait C { function c1() {} //error2054 static function c2() {} private static function c3() {} }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_misspelling_recovery.php
<?hh $i = 1; do { echo "$i\t".($i * $i)."\n"; // output a table of squares ++$i; } whike ($i <= 10); // report 'whike' as misspelled // Known issue: something about the location reported by current_token_text // in full_fidelity_parser_helpers is tripped up enough enough by newlines // that the misspelling recovery doesn't work on this 'whike'. $i = 1; do { echo "$i\t".($i * $i)."\n"; // output a table of squares ++$i; } whike ($i <= 10); // Known cases that this error recovery improvement does not address. // These are still not-recovered-from because the require_[TokenKind] // methods are not invoked when parsing them. $doublerl = ($p) =>> $p * 2; // ideally would report '=>>' as misspelled $doublerl = ($p) ==g $p * 2; // ideally would report '==g' as misspelled
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_misspelling_recovery2.php
<?hh // strict abstract ckass C { // error1058 } final interfsce I { // error1058 } abstract final ttait T { // error1058 } // Error recovery in this case remains unsophisticated, though. ckass C { }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_mixed_bracketed_unbracketed_namespaces1.php
<?hh // strict namespace foo; namespace bar {} namespace blah {} namespace blah2; namespace outer { namespace inner; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_mixed_bracketed_unbracketed_namespaces2.php
<?hh // strict namespace foo {} namespace bar; namespace blah {} namespace blah2; namespace outer { namespace inner; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_namespace.php
<?hh namespace {} namespace SampleNamespace {} namespace SampleNamespace; namespace SampleNamespace { function f () {} class C {} } namespace { function f () {} class C {} }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_namespace_error_recovery.php
<?hh namespace NS1 // error1038, and recover to declaration level class C1 { } interface I1 { } trait T1 { } namespace NS2; // error2052, cannot mix bracketed and unbracketed namespaces class C2 { } interface I2 { } trait T2 { } namespace NS3 { // no error class C3 { } interface I3 { } trait T3 { } } // NS4 demonstrates a case of suboptimal error recovery. The hypothetical // programmer writing it probably just forgot a left brace after 'NS4', but the // FFP reports error1038 and an extra right brace. Still, this isn't too // bad--these messages should do a reasonable job of nudging the programmer // towards the actual mistake. // TODO T20730184: currently the FFP gives the error "An expression is expected // here." when encountering an unexpected right brace. Change this to something // clearer, like "This right brace does not have a corresponding left brace." namespace NS4 // error1038, and recover to declaration level class C4 {} interface I4 { } trait T4 { } } // report extra right brace here namespace NS5 { class C5 { } interface I5 { } trait T5 { } // report missing right brace here
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_null_coalesce_assignment.php
<?hh // strict function foo(int $y): int { return $y; } function f(?int $x): int { $x ??= 0; $y = 3; return $x ??= $y |> foo(); }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_object_creation_errors.php
<?hh // strict $p1 = new Point; // error2038 $p1 = new Point(); // legal $p1 = new Point 12, 34; // error2038, among others $p1 = new Point(12); // legal $p1 = new RReeaallllyyLLoonnggNNaammee; // error2038 $p1 = new $PointClassVar->$pointClassName(); // legal $p1 = new 'Point'(12); // not a class-type-designator $p1 = new Point::Point(12); // not a class-type-designator $p1 = new Point::$pointVar(12); // legal $p1 = new Point::Point::$pointVar(12); // not a class-type-designator $p1 = new Point::$pointVar::$pointVar(12); // legal $p1 = new $point(12); // legal $p1 = new Point<int>(12); // legal $p1 = new (function_that_returns_class_name())(12); // legal $p1 = "Point" |> new $$(12); // legal
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_php_blocks_errors.php
<?hh function foo() { $a = 1; } ?> <?hh class foo { public function bar(): int { return 5; } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_prefixed_string.php
<?hh function f() : void { $x = "It"; $y = "worst"; $z = f"{$x} was the {$y} of times"; $w = re"blah blah"; $a = re""; // Consistent with `aks-A124jk12jhd()`; Parses as `aks` minus prefixed string $a0 = aks-A124jk12jhd"sosdk!nwekje@"; // Parses as prefixed string $a1 = aksA124jkhgf12jhdddsljs"sosdk!nwekje@"; // Parser error; `re!interpolator` is not a name $a2 = re!interpolator"Hello"; $b = re"//"; $b0 = aaaaaa"aaaaaa"; $c = re"/(.?)/"; $d = re"/.*/"; $e = $c.$d; $f = re"//".re"//"; $g = Regex\re"//"; $h = Foo\FooInterpolator""; // Single quotes $w = re'blah blah'; $a = re''; // Consistent with `aks-A124jk12jhd()`; Parses as `aks` minus prefixed string $a0 = aks-A124jk12jhd'sosdk!nwekje@'; // Parses as prefixed string $a1 = aksA124jkhgf12jhdddsljs'sosdk!nwekje@'; // Parser error; `re!interpolator` is not a name $a2 = re!interpolator'Hello'; $b = re'//'; $b0 = aaaaaa'aaaaaa'; $c = re'/(.?)/'; $d = re'/.*/'; $e = $c.$d; $f = re'//'.re'//'; $g = Regex\re'//'; $h = Foo\FooInterpolator''; // TODO(T19708752): Enable qualified names as prefixes // $i = \HH\Lib\Private\Foo\FooInterpolator""; // $j = Private\Foo\FooInterpolator""; // $h0 = Foo\FooInterpolator"hello$firstname{$lastname}, goodbye"; // $i0 = \HH\Lib\Private\Foo\FooInterpolator"hello$x, goodbye"; // $j0 = Private\Foo\FooInterpolator"hello$x, goodbye"; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_readonly_parsing.php
<?hh class Foo { } // Can technically use this function to readonlyfy things function ro<T>(T $x) : readonly T { return $x; } async function returns_readonly() : readonly Awaitable<Foo> { return new Foo(); } async function returns_normal(): Awaitable<Foo> { return new Foo(); } async function expressions(readonly Foo $x) : readonly Awaitable<Foo> { // lambda $f = (readonly Foo $y) : readonly Foo ==> { return $y;}; // function $z = function(readonly Foo $f) : readonly Foo { return $f; }; $r = readonly new Foo(); $w = $z(readonly $r); $readonly_first = readonly await returns_normal(); $await_readonly = await readonly returns_readonly(); // This should parse, but won't typecheck and will fail at runtime // because returns_readonly returns a readonly value, it must be explicitly // cast to readonly $readonly_first_readonly = readonly await returns_readonly(); // like below // note that the first readonly is redundant, just testing parsing. $correct = readonly await readonly returns_readonly(); return $x; } function closure_type_spec( (readonly function(readonly Foo, readonly Bar) : readonly Foo) $f ) : readonly (function(): void) { } class Bar { public readonly Foo $x; public function __construct( public readonly Foo $y, ) { $this->x = new Foo(); } public readonly function getFoo() : void { $f = /* <<readonly>> */ (Foo $y) ==> {return $y;}; // TODO: readonly annotation on anonymous function $z = readonly function(Foo $f) : void { }; } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_reified_generics.php
<?hh class C<reify +T1, -T2, reify T3>{} function f<reify T1, T2, reify T3>(int $x) {} f<reify int, string, reify bool>(1); new C<reify int, string, reify bool>();
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_reified_generic_attributes.php
<?hh // strict function f<<<__Attr>> reify T>() {} function g< <<__Attr>> reify U>() {} function h<reify V>() {} class C { const type TyC<<<Attr>> T> = int; public function ff<<<__Attr>> reify Tt>() {} public function gg< <<__Attr>> reify Uu>() {} public function hh<reify Vv>() {} } class CC<<<__Attr>> reify Tt>{} class DD< <<__Attr>> reify Tt>{} class EE<reify Tt>{} type Ty<<<Attr>> T> = int; newtype Ty2<<<Attr>> T> = int;
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_shapes.php
<?hh // strict shape(1 => 1); shape(true => 1); shape($x => 1); shape("hi" => 1); shape("1hi" => 1); shape(2 => 1, 3 => 4);
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_soft_attribute.php
<?hh type t = <<__Soft>> darray<int, <<__Soft>> string>; type u = varray<<<__Soft>> int>; function f<T>(): void {} function g(<<__Soft>> int $_): <<__Soft>> string { f<<<__Soft>> float>(); return "hello"; } abstract class C { <<__Soft>> protected float $x; const type T = <<__Soft>> int; public async function f(): Awaitable<<<__Soft>> int> { return 42; } } class D { const <<__Soft>> int X = 0; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_statements.php
<?hh function foo() { if ($a) if ($b) switch ($c) { case 123: fallthrough; // fallthrough parsed but not yet supported default: break; } else return $d; else if($e) do { while($f) throw $g; continue; } while ($h); }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_statement_errors.php
<?hh function bar() : void { case 123: ; // error, outside switch default: ; // error, outside switch switch ($x) { case 123: ; default: break;} // no error break; // error while($a) { if ($b) break; // no error if ($c) continue; // no error $x = function($b) { break; }; // error } try {} catch (Exception $ex) {} // no error try {} finally {} // no error try {} // error switch ($x) { } // error switch ($x) { foo(); } // error switch ($x) { foo(); foo(); } // error }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_string_interpolation_errors.php
<?hh function okay() { $a = "$b"; $a = "$b->c"; $a = "$b[0]"; $a = "$b[$c]"; $a = "$$b"; // Note: only `$b->c` is interpolated, and `->d` is left as a literal string. $a = "$b->c->d"; // Note: only `$b[0]` is interpolated, and `[1]` is left as a literal string. $a = "$b[0][1]"; // Note: only `$b` is interpolated, and `\[0]` is left as a literal string. $a = "$b\[0]"; $a = "${b}"; $a = "${b[0]}"; $a = "${b[ 0 ]}"; $a = "${b['data']}"; $a = "${ b }"; $a = "${$b}"; $a = "${b + 1}"; $a = "${b.""}"; $a = "${b && 1}"; $a = "${b !== 1}"; $a = "${b < 1}"; $a = "${b ?? 1}"; $a = "${b(print('foo'))}"; $a = "${b[print('foo')]}"; $a = "${b ? 1 : 2}"; $a = "${$b}"; // These are effectively parsed as referring to the constant `b` instead of // the variable `b`. If they were parsed as if they were referring to the // variable `b`, then only a single layer of subscripting would be permitted. $a = "${ b[0][1]}"; $a = "${b [0][1]}"; // Note: actually illegal in PHP (because member access is illegal on // constants), but caught by the typechecker. HHVM throws a runtime error. $a = "${b->c}"; // Still interpolates `$b` and `$c`, but doesn't fail because of the `{$` in // the middle of the string. $a = "\{$b foo $c\}"; $a = "{$b[1]}"; $a = "{$b[1][2]}"; $a = "{$b[1]()}"; $a = "{$b[1]->c}"; $a = "{$b[1]->c[2]}"; $a = "{$b[print('hello')]}"; $a = "{$b->c}"; $a = "{$b[1]->c[2]}"; $a = "{$b()}"; $a = "{$b(c(1 + 2))}"; $a = "{$b()[1]}"; $a = "{$b()->c}"; $a = "{$$b}"; } function not_okay() { $a = "$b["; $a = "$b[]"; $a = "$b[0"; $a = "$b[ 0]"; $a = "$b[0 ]"; $a = "$b[$$c]"; $a = "$b[$c->d]"; $a = "$b[0\]"; $a = "${b[0][1]}"; $a = "${b = 1}"; $a = "${b += 1}"; $a = "{$b"; $a = "{$b foo $c}"; $a = "{$b is C}"; $a = "{$b.$c}"; $a = "{$b + 1}"; $a = "{$b = 1}"; $a = "{$b !== 1}"; $a = "{$b ?? 1}"; $a = "{$b[1] . 'c'}"; $a = "{$b() . 'c'}"; $a = "{$b::C}"; $a = "{$b++}"; $a = "{$b ? 1 : 2}"; // Note: actually parses in PHP but appears to be mostly useless. At runtime, // looks up the static property literally named '$c'. $a = "{$b::$c}"; } function implementation_defined_okay() { $a = "{$b?->c}"; $a = "{$b->c()?->d}"; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_trailing_commas.php
<?hh // strict /** * Test cases for trailing commas in (sometimes) unexpected places. Try to do * this with *and* without line breaks (where trialing commas may add value). */ class Plain { } class Parametric<T,> { } function foo(dict<int,Plain,> $x): dict< int, Plain, > { return $x; } function bar(keyset<int,> $x): keyset< int, > { return $x; } function baz(vec<Plain,> $x): vec< Plain, > { return $x; } function qux(Parametric<T,> $x): Parametric< T, > { return $x; } function quux<T>(classname<T,> $x): classname< T, > { return $x; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_trivia.php
<?hh // strict /** * Test case with various trivia such as end of line, fixme, whitespace * and comments */ function foo(dict<int,Plain,> $x): dict< int, Plain, > { /* HH_FIXME: Some fixme */ return $x; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_tuple_type_keyword.php
<?hh // strict class Foo { public function bar(): tuple<int,string> { return tuple(1, 'baz'); } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_type_alias.php
<?hh // strict type T1<T> = T2; type T2 = T2; type T3<T> = T3; type T4<T, T> = T; type T5<int, T> = T;
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_type_const.php
<?hh class C { const type T1 = int; const type T2 as T1 = T1; } abstract class A { abstract const type T0; abstract const type T1 as string; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_variadic_ref_decorators.php
<?hh // strict function variadic(mixed ... $x) : void {} function ref(int & $x) : void {} function varvar(mixed ... ... $x) : void {} function refref(int & & $x) : void {} function varref(int ... & $x) : void {} function refvar(mixed & ... $x) : void {}
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_varray_darray_expressions.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class TestVarrayDarrayExpression { private static function foo(): void { darray['bar' => 0, 'baz' => 1, 'qux' => 2]; varray[false, true]; } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_varray_darray_types.php
<?hh // strict final class VarrayDarrayTypesTest { use DarrayTrait<darray<string,string>>; use VarrayTrait<varray<string>>; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_visibility_modifier_errors.php
<?hh // strict interface I1 { function i1(): void; // legal public function i2(): void; // legal private function i3(): void; // error2047 protected function i4(): void; // error2047 static final function i1(): void; // legal static final public function i2(): void; // legal static final private function i3(): void; // error2047 static final protected function i4(): void; // error2047 }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_xhp_attributes.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class C { attribute SomeAttributeType attr_name, SomeAttributeType parent, // allow using a keyword as a name OtherAttributeType self; // and another }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_xhp_attribute_enum_errors.php
<?hh //strict class :Foo { attribute enum {} a; // error attribute enum {"xy", 'z', 123} b; // legal attribute enum {true, false} c; // error attribute enum {1.0} d; // error }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_xhp_lexing.php
<?hh return <a> << </a>; return <a> < </a>; return <a> <= </a>; return <a> <=> </a>; return <a> <<= </a>; return <a> <> </a>; return <a> << something </a>; return <a> < something </a>; return <a> <= something </a>; return <a> <=> something </a>; return <a> <<= something </a>; return <a> <> something </a>;
PHP
hhvm/hphp/hack/test/full_fidelity/cases/test_xhp_repeated_decl_errors.php
<?hh // strict class :foo { children empty; children empty; } class :bar { category %foo; category %foo; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/this_in_static.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ class Foo { public static function toto() { return $this->bar(); } }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/type-const_multiple-as-bounds_experimental.php
<?hh abstract class A { abstract const type T0; abstract const type T1 as string; abstract const type T2 as arraykey as int; abstract const type T3 as int as arraykey as num = int; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/type-const_super-bound_experimental.php
<?hh abstract class BadWithoutExperimental { abstract const type T super string; abstract const type Tdflt super int = num; abstract const type Tboth1 as arraykey super string; abstract const type Tboth2 super string as arraykey; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/type-refinement_experimental.php
<?hh interface I {} type InAlias = I with { type T as int; ctx C = []; }; function in_fun_hint( (function(I with { type T = int }): string) $_, ): void {} interface F { public function in_abstr_method_return_type( ): Box with { ctx C super [globals] }; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/typed_local.php
<?hh <<file:__EnableUnstableFeatures('typed_local_variables')>> function f() : void { let $x : int = 1; let int $x = 1; let $x : int : 1; let $x: int; let $x int; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/type_constant_attributes.php
<?hh abstract class C { <<__Enforceable>> abstract const type T as num; abstract const type Tu as num; <<__Enforceable>> const type Tv = int; const type Tw = int; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/use_const_as.php
<?hh namespace consts { const x = "x"; } use const consts\x as a; use const consts\x as b; use const consts\x as c; use const consts\x as d; use const consts\x as a;
PHP
hhvm/hphp/hack/test/full_fidelity/cases/abstract_static_props/abstract_const_init.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. abstract class A { <<__Const>> abstract static public int $a = 5; abstract const int C = 5; } class B { <<__Const>> static public int $b; const int C; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/abstract_static_props/abstract_private_prop.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. abstract class A { private abstract static int $p; protected abstract static int $l; public abstract static int $m; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/abstract_static_props/abstract_static_prop.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class A { abstract public static int $p; abstract public int $l; <<__Const>> abstract public static int $m; <<__Const>> abstract public int $n; }
PHP
hhvm/hphp/hack/test/full_fidelity/cases/atted_attribute_syntax/test_atted_edge_cases.php
<?hh class :test { attribute int id @required; attribute string name @lateinit; } @@Attr function f(): void {} @Attr @ function g(): void {}
PHP
hhvm/hphp/hack/test/full_fidelity/cases/await_as_an_expression/await_as_an_expression_assignment_inside_lambda.php
<?hh async function foo(): Awaitable<void> { $x = await async { $x = 42; }; $x = await async { if ($x = 42) {} }; }