language
stringlengths 0
24
| filename
stringlengths 9
214
| code
stringlengths 99
9.93M
|
---|---|---|
PHP
|
hhvm/hphp/hack/test/typecheck/delayed_subst4.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
interface I1<T> {
public function call(T $in): bool;
}
interface I2<T> extends I1<T> {}
abstract class TestXXX<T> implements I1<T>, I2<T> {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/delayed_subst5.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
final class Child extends Base<int> {
use ATrait;
}
trait ATrait {
require extends Base<mixed>;
}
class Base<+T> {
public function get(): T {
throw new Exception();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/deprecated_class_meth.php
|
<?hh // strict
class X {
<<__Deprecated('use bar() instead')>>
public static function foo(): void {}
}
function f(): (function(): void) {
return X::foo<>;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/deprecated_escaped_message.php
|
<?hh
<<__Deprecated('testing \n \t \\ \''.' foo')>>
function foo(): void {}
function f(): void {
foo();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/deprecated_fun.php
|
<?hh
<<__Deprecated('use bar() instead')>>
function foo(): void {}
function f(): void {
foo();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/deprecated_method.php
|
<?hh
class F {
<<__Deprecated('use bar() instead')>>
public static function foo(): void {}
}
function f(): void {
F::foo();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/deprecated_meth_caller.php
|
<?hh // strict
class X {
<<__Deprecated('use bar() instead')>>
public function foo(): void {}
}
function test(): (function(X): void) {
return meth_caller('X', 'foo');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dep_type_bug.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function foo(I $i): void {
$x = $i->getJ();
$x->bar($i);
}
interface I {
public function getJ(): J<this>;
}
interface J<-Tj as I> {
public function bar(Tj $x): void;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/destructor.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 function __destruct() {
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/desugar_tuple.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 foo((int, int) $thing): void {
list($v, $x) = $thing;
$v[] = 12;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/desugar_tuple2.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 foo((int, int, int) $thing): void {
list($v, $x) = $thing;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dict_const.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
const dict<string, string> empty_dict = dict[];
const dict<int, string>
dict_const_element = dict[1 => 'foo', 2 => 'bar', 3 => 'baz'];
const dict<string, vec<dict<string, int>>>
nested_dict = dict['foo' => vec[dict['baz' => 5]]];
const dict<string, (function(): int)>
dict_with_illegal_elements = dict['foo' => () ==> 1];
|
PHP
|
hhvm/hphp/hack/test/typecheck/div_abstract.php
|
////file1.php
<?hh // strict
newtype MyFloat as float = float;
////file2.php
<?hh // strict
function MyDiv(MyFloat $x, MyFloat $y): float {
return $x / $y;
}
function MyDivAlt<Tx as float, Ty as float>(Tx $x, Ty $y): float {
return $x / $y;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/div_union.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function inverseCDF(float $p, int $n): float {
$v = 0.5;
$dv = 0.5;
$x = 0.0;
while ($dv > 1e-15) {
$x = 1 / $v - 1;
$dv = $dv / 2;
if (cdf($x, $n) < $p) {
$v = $v - $dv;
} else {
$v = $v + $dv;
}
}
return $x;
}
function cdf(float $x, int $n): float {
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/do1.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(bool $b): int {
$x = null;
do {
if ($b) {
continue;
}
$x = 0;
} while ($b);
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/do2.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(): int {
$x = null;
do {
for ($i = 0; $i < 10; ++$i) {
continue;
}
$i = 0;
while ($i++ < 10) {
continue;
}
do {
continue;
} while ($i-- > 0);
$x = 0;
} while (true);
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dollar_xhp.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 Bloo {
public function mybloo(): void {
$x = <div>$</div>;
}
}
class :div extends XHPTest {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/double_argument.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.
*
*
*/
function foo(double $x): void {
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/double_cast.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.
*
*
*/
function foo(int $x): float {
return (double)$x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/double_null.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 Env {}
class MyBox<T> {
private T $data;
public function __construct(T $x) {
$this->data = $x;
}
public function get(): ?T {
return $this->data;
}
}
function nnull<T>(?T $x): T {
if($x === null) {
throw new Exception('should not happen');
}
return $x;
}
class X {
private ?Env $x;
public function test(): Env {
$blah = new MyBox($this->x);
$maybe_env = nnull($blah->get());
return $maybe_env;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/double_nullable.php
|
<?hh
function bar(): darray<int, ?int> {
return darray[123 => null, 456 => 789];
}
function idx2<Tk as arraykey, Tv>(?KeyedContainer<Tk, Tv> $collection, ?Tk $index): ?Tv {
return idx($collection, $index);
}
function foo(): int {
$a = idx2(bar(), 123);
if ($a !== null) {
return $a;
}
return 345;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/double_nullable2.php
|
<?hh
function bar(): darray<int, ?int> {
return darray[123 => null, 456 => 789];
}
function idx2<Tk as arraykey, Tv>(?KeyedContainer<Tk, Tv> $collection, ?Tk $index): ?Tv {
return idx($collection, $index);
}
function foo(): ?int {
$a = idx2(bar(), 123);
return $a;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/double_nullable_through_await.php
|
<?hh // strict
class Bar {
public async function maybeFoo(): Awaitable<?Foo> {
return null;
}
}
class Foo {}
function maybe_bar(): ?Bar {
return new Bar();
}
async function test(): Awaitable<void> {
$bar = maybe_bar();
$foo = await $bar?->maybeFoo();
hh_show($foo);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/double_nullable_through_idx.php
|
<?hh // strict
class Foo {}
function getFoos(): dict<string, ?Foo> {
return dict['test' => new Foo()];
}
function test(): void {
$foos = getFoos();
$foo = idx($foos, 'test');
hh_show($foo);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/do_cond.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 blah(?int $x): void {
if ($x !== null) {
do {
$x += 5;
$x = null;
} while ($x !== null);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/do_cond2.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 blah(?int $x): void {
if ($x !== null) {
do {
$x += 5;
$x = null;
} while ($x > 5);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/do_cond3.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 myfunctionname(?int $meh): void {
do {
} while($meh == null);
$meh = $meh + 5;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/do_typechange.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.
*
*
*/
function foo(bool $b): int {
$x = 10;
do {
$x = null;
} while($b);
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/do_while_condition_typechange.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 meh_while(int $i): void {
$x = $i;
do {
$i += $x;
} while($x = true);
}
|
hhvm/hphp/hack/test/typecheck/dune
|
(rule
(alias typecheck)
(deps %{exe:../../src/hh_single_type_check.exe}
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/review.sh
%{project_root}/hack/test/hhi/coeffects.hhi
%{project_root}/hack/test/hhi/expr_tree.hhi
%{project_root}/hack/test/hhi/XHPTest.hhi
(glob_files_rec %{project_root}/hack/test/typecheck/**.json)
(glob_files_rec %{project_root}/hack/test/typecheck/**.exp)
(glob_files_rec %{project_root}/hack/test/typecheck/**.php-only-typecheck)
(glob_files_rec %{project_root}/hack/test/typecheck/**.php)
(glob_files_rec %{project_root}/hack/test/typecheck/**HH_FLAGS))
(action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/typecheck
--program %{exe:../../src/hh_single_type_check.exe}
--batch
--flags
--enable-sound-dynamic-type
--error-format plain)))
(rule
(alias decl_compare)
(deps %{exe:../../src/hh_single_type_check.exe}
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/review.sh
%{project_root}/hack/test/hhi/coeffects.hhi
%{project_root}/hack/test/hhi/expr_tree.hhi
%{project_root}/hack/test/hhi/XHPTest.hhi
(glob_files_rec %{project_root}/hack/test/typecheck/**.decl_exp)
(glob_files_rec %{project_root}/hack/test/typecheck/**.php)
(glob_files_rec %{project_root}/hack/test/typecheck/**HH_FLAGS))
(action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/typecheck
--program %{exe:../../src/hh_single_type_check.exe}
--batch --out-extension .decl_out --expect-extension .decl_exp --flags --decl-compare)))
(rule
(alias typecheck_w_timeout)
(deps %{exe:../../src/hh_single_type_check.exe}
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/review.sh
%{project_root}/hack/test/hhi/coeffects.hhi
%{project_root}/hack/test/hhi/expr_tree.hhi
%{project_root}/hack/test/hhi/XHPTest.hhi
(glob_files_rec %{project_root}/hack/test/typecheck/**.json)
(glob_files_rec %{project_root}/hack/test/typecheck/**.exp)
(glob_files_rec %{project_root}/hack/test/typecheck/**.php-only-typecheck)
(glob_files_rec %{project_root}/hack/test/typecheck/**.php)
(glob_files_rec %{project_root}/hack/test/typecheck/**HH_FLAGS))
(action (run %{project_root}/hack/test/verify.py %{project_root}/hack/test/typecheck
--program %{exe:../../src/hh_single_type_check.exe}
--timeout 20
--verbose
--flags
--enable-sound-dynamic-type
--error-format plain)))
(alias
(name runtest)
(deps
(alias typecheck)
(alias decl_compare)))
|
|
PHP
|
hhvm/hphp/hack/test/typecheck/duplicate_class_declaration.php
|
<?hh
class Foo { public function foo(): void {} }
class Foo { public function bar(): void {} } // error
function f(): void {
$foo = new Foo();
$foo->foo(); // ok
$foo->bar(); // error
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/duplicate_use.php
|
<?hh
namespace A {
function foo(): void {}
}
namespace B {
function foo(): void {}
}
namespace C {
use function A\foo;
use function B\foo;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_class.php
|
<?hh
class Foo {
public static function bar(): void {}
}
function f(): void {
$a = 'Foo';
/* This is okay since we are in partial mode */
$a::bar();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_class_2.php
|
<?hh // strict
class Foo {
public static function bar(): void {}
}
function f(Foo $a): void {
// make $a into Tunion
if (true) {
}
$a::bar(); // should still work
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_class_bad.php
|
<?hh // strict
class Foo {
public static function bar(): void {}
}
function f(): void {
$a = 'Foo';
$a::bar();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_new1.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 C {}
function f(): void {
$a = darray['foo' => 'C'];
new $a['foo']();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_new2.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 C {}
function f(): void {
$a = darray['foo' => 'C'];
new $a['foo']();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_new3.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 C {}
function f(): string {
return 'C';
}
function g(): C {
return new (f())();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_new4.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 C {}
function f(): string {
return 'C';
}
function g(): C {
return new (f())();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_new5.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 C {
public string $s = 'C';
}
function f(): void {
$c = new C();
$cc = new $c->s();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_new6.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 C {
public string $s = 'C';
}
function f(): void {
$c = new C();
$cc = new $c->s();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_new7.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 C {
public static string $s = 'C';
}
function f(): void {
new C::$s();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_new8.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 C {
public static string $s = 'C';
}
function f(): void {
new C::$s();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_new_object.php
|
<?hh
function takes_int(int $_): void {}
function f(string $str): void {
$o = new $str(); // Type error
takes_int($o); // Terr passes as int
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_props1.php
|
<?hh
class A {
const int c = 1;
public static string $f1 = "42";
}
function f(): void {
$a = A::c; // no errors
$b = A::$f1; // no errors
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/dynamic_props2.php
|
<?hh // strict
class A {
const c = 1;
public static $f1 = "42";
}
function f() {
$a = A::c; // no errors
$b = A::$f1; // no errors
$n = "f";
$c = A::${$n . "1"}; // error in strict mode
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/early_solve_inter.php
|
<?hh
function test(Vector<int> $v): void {
$m = Map {};
foreach ($v as $i) {
if ($m->containsKey("a")) {
$current_m = $m->get("a");
if ($current_m !== null) {
$current_m->add($i);
}
} else {
$m["a"] = Vector {$i};
}
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/early_solve_inter2.php
|
<?hh
function test(Vector<int> $v): void {
$m = Map {};
foreach ($v as $i) {
if ($m->containsKey("a")) {
$current_m = $m->get("a");
if ($current_m is nonnull) {
$current_m->add($i);
}
} else {
$m["a"] = Vector {$i};
}
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/echo_class_const.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class A {
const string RESET = "hello";
private static function echoMessage(): void {
echo self::RESET;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/eif_define_var.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 getint(): ?int {
return 1;
}
function f(): ?int {
return ($x = getint()) ? $x : 0;
}
function g(): bool {
if (true) {
$y = ($x = getint()) ? 1 : 0;
} else {
$x = 0;
$y = 0;
}
return $x && $y;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/elseif.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.
*
*
*/
function meh(): void {
if (true) {
return;
} elseif (false) {
return;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/elseif2.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(): void {
if (true) {
} elseif (false) {
} else {
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/elseif3.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(): void {
if(true) {
} elseif 0;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/encapsed1.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(): string {
$clauses = '';
$prefix = '';
return "(term {$prefix}{$clauses})";
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enumname.php
|
<?hh // strict
enum Foo: int as int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
function foo<T>(HH\enumname<T> $input): void {}
function bar<T>(enumname<T> $input): void {}
type enumname<T> = HH\enumname<T>;
const enumname<arraykey> BUILTIN_ENUM = HH\BUILTIN_ENUM;
function test(): void {
foo(Foo::class);
bar(Foo::class);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_API_likeness.php
|
<?hh
enum E: int {
A = 42;
B = 43;
}
function main(): void {
hh_expect_equivalent<dict<string,E>>(E::getValues());
hh_expect_equivalent<dict<E,string>>(E::getNames());
hh_expect_equivalent<bool>(E::isValid(42));
hh_expect_equivalent<?E>(E::coerce(42));
hh_expect_equivalent<E>(E::assert(42));
hh_expect_equivalent<Container<E>>(E::assertAll(vec[42]));
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_as_class.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.
*
*
*/
enum SomeEnum: string as string {
test1 = "testString1";
test2 = "testString2";
}
function foo(): classname<SomeEnum> {
return SomeEnum::class;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_as_class_input.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.
*
*
*/
enum NumbahsEnum: int as int {
value1 = 1;
value2 = 2;
lifeValue = 42;
}
function bar(classname<NumbahsEnum> $test): int {
return NumbahsEnum::lifeValue;
}
function foo(): int {
return bar(NumbahsEnum::class);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_as_false_input.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.
*
*
*/
enum DerpyEnum: string as string {
test1 = "haha";
test2 = "DERP";
}
enum BaitEnum: string as string {
test1 = "haha";
test2 = "DERP";
}
function foo(): classname<DerpyEnum> {
return BaitEnum::class;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_base_cycle.php
|
<?hh
enum E : E {}
enum E0 : E1 {}
enum E1 : E2 {}
enum E2 : E0 {}
/* enum XXX : self {} // not allowed */
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_class_enumerator_attr.php
|
<?hh
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*/
// Attribuets are allowed on type constants, but not on enumerators
enum class E : int {
<<__Enforceable>> // allowed
const type T = int;
<<__Enforceable>> // not allowed
int A = 42;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_eq_bad.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum E: int {
A = 1;
B = 2;
}
enum F: int {
C = 2;
D = 3;
}
function TestIt(): void {
$x = E::A;
$y = F::C;
if ($x === $y) {
echo 'same';
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_eq_good.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum E: int as int {
A = 1;
B = 2;
}
enum F: int as int {
C = 2;
D = 3;
}
function TestIt(): void {
$x = E::A;
$y = F::C;
if ($x === $y) {
echo 'same';
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_exh_default_with_extra.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.
*
*
*/
enum E: int {
A = 1;
B = 2;
}
function TestIt(E $e, arraykey $k, bool $b): void {
if ($b) {
$e = $k;
}
switch ($e) {
case E::A:
echo 'A';
break;
case E::B:
echo 'B';
break;
default:
echo 'other';
break;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_stringish_bad_1.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum E: string {
FOO = 'foo';
BAR = 'bar';
}
function test(E $x): Stringish {
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_stringish_bad_2.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum E: int as int {
FOO = 1;
BAR = 2;
}
function test(E $x): Stringish {
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_stringish_good.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum E : string as string {
FOO = 'foo';
BAR = 'bar';
}
function test(E $x): Stringish {
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_subtyping.php
|
<?hh
enum E: int as int {}
abstract class A {
/* HH_FIXME[2053] */
abstract const type T as HH\BuiltinEnum<string>;
}
class C extends A {
const type T = E;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/enum_xhp_child.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum E1: int {
A = 1;
B = 2;
}
function test1(E1 $e1): XHPChild {
return $e1;
}
enum E2: int as arraykey {
X = 42;
Y = 1337;
}
function test(E2 $e2): XHPChild {
return $e2;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/equal1.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.
*
*
*/
interface I {}
class A implements I {}
class B implements I {}
function createFromMeta(): ?I {
$result = null;
switch (0) {
case 0:
$result = new A();
break;
case 1:
$result = new B();
break;
default:
$result = null;
break;
}
if ($result === null) {
throw new Exception('Cannot create corrector %d.');
}
return $result;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/eq_constraint.php
|
<?hh // strict
class Foo {
public function assertIsFoo(): void {}
}
class Boxing<Tclass> {
public function __construct(
private Tclass $member,
) {}
public function getWithDefault<Tinner>(
Tinner $default,
): Tinner where
Tclass = ?Tinner,
{
return $this->member ?: $default;
}
public function getOrExcept<Tinner>(): Tinner where Tclass = ?Tinner {
if ($this->member === null) {
throw new Exception('Member is null and can\'t be got.');
}
return $this->member;
}
public function getAsIs(): Tclass {
return $this->member;
}
public static function caller(Boxing<?Foo> $c, Foo $f): void {
$c->getWithDefault($f)->assertIsFoo(); // Must succeed
$c->getOrExcept()->assertIsFoo(); // Must succeed
$c->getAsIs()->assertIsFoo(); // Must fail, because may be null
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/erling_loop.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(): int {
$x = 0;
$y = 1;
$z = 2;
for ($i = 0; $i < 3; $i++) {
$x = $y;
$y = $z;
$z = 'hello';
}
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/erling_loop2.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<T> {
public ?T $x, $y, $z;
}
function test(): int {
$obj = new X();
$obj->x = 0;
$obj->y = 1;
$obj->z = 2;
for ($i = 0; $i < 3; $i++) {
$obj->x = $obj->y;
$obj->y = $obj->z;
$obj->z = 'hello';
}
return $obj->x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/erling_loop3.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(): int {
$x = 0;
$y = 1;
$z = 2;
for ($i = 0; $i < 3; $i++) {
list($x) = tuple($y);
list($y) = tuple($z);
list($z) = tuple('hello');
}
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/erling_loop4.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(): int {
$x = 0;
$y = 1;
$z = 2;
for ($i = 0; $i < 3; $i++) {
$x = (Vector { $y })[0];
$y = (Vector { $z })[0];
$z = (Vector { 'hello' })[0];
}
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/erling_loop5.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<T> {
public function __construct(private T $data) {}
public function set(T $x): void {
$this->data = $x;
}
public function get(): T {
return $this->data;
}
}
function test(): int {
$obj = new X(0);
$x = 0;
$y = 1;
$z = 2;
for ($i = 0; $i < 3; $i++) {
$obj->set($y);
$x = $obj->get();
$obj->set($z);
$y = $obj->get();
$obj->set('hello');
$z = $obj->get();
}
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/erling_loop6.php
|
<?hh
function test(): int {
$w = 0;
$x = 1;
$y = 2;
$z = 3;
for ($i = 0; $i < 3; $i++) {
$w = $x;
for ($j = 0; $j < 3; $j++) {
$x = $y;
$y = $z;
}
$z = 'hello';
}
return $w;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/erling_loop7.php
|
<?hh
function test(): int {
$w = 0;
$x = 1;
$y = 2;
$z = 3;
for ($i = 0; $i < 3; $i++) {
$w = $y;
for ($j = 0; $j < 3; $j++) {
$x = $w;
$y = $z;
$z = 'hello';
}
}
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/evade_enum_exhaustivity.php
|
<?hh
enum E: string as string {
A = "a";
B = "b";
}
class C {
public function getEnumWrong(): E { return E::A;}
}
function main(): void {
$e = (new C())->getEnumWrong();
switch ($e) {
case E::A:
break;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/exact_class_match.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function testit(Super $tf, Sub $s):void {
// This works
// bar<Super>(async (C<Super> $step) ==> new Super());
// This does not, with --new-inference, because Hack infers `Sub` for Tv
// Then C<Sub> does not unify with C<Sub>
bar(async (C<Super> $step) ==> $s);
}
function bar<Tv>((function (C<Tv>): Awaitable<Tv>) $f): Tv {
throw new Exception();
}
final class C<Tv> {
}
class Super {
}
class Sub extends Super { }
|
PHP
|
hhvm/hphp/hack/test/typecheck/exact_or_final.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
final class D {
public function addBranch(
this $branch,
): this {
return $branch;
}
}
function testit(D $subtree):void {
$tree = new D();
$tree->addBranch($subtree);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/exit_terminal_check.php
|
<?hh
function main(): void {
try {
$foo = 'bar';
} catch (Exception $e) {
exit();
}
var_dump($foo);
}
function main2(): int {
if (true) {
$x = 1;
} else {
exit(1);
}
return $x;
}
function main3(bool $a): int {
if ($a) {
return 1;
} else {
exit(1);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/expected_constvec.php
|
<?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class C {
public function foo():int { return 3; }
}
function test1():ConstVector<(function(C):int)> {
return ImmVector { $x ==> $x->foo() };
}
function test2():MutableVector<(function(C):int)> {
return Vector { $x ==> $x->foo() };
}
function test3():ConstMap<int,(function(C):int)> {
return ImmMap { 1 => $x ==> $x->foo() };
}
function test4():MutableMap<int,(function(C):int)> {
return Map { 1 => $x ==> $x->foo() };
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/exponential_1.php
|
<?hh // strict
function foo(): void {
$a = 10;
$b = $a ** 10; // num
$c = 3 ** $b; // num
expect_num($b);
expect_num($c);
$d = ($c === $a ** $b ** $c);
expect_bool($d);
$e = ((int)$d) ** 3.5;
expect_float($e);
$e = $e ** 100000;
expect_float($e);
$i = 1;
$f = 3.5;
$a = 1 ** 1.0; // float
expect_float($a);
$b = 1.0 ** 1; // float
expect_float($b);
$c = 1.0 ** 1.0; // float
expect_float($c);
expect_num(100000000 ** 10000000); // num
expect_num(2 ** 2); // num
}
function expect_float(float $x): void {}
function expect_num(num $x): void {}
function expect_bool(bool $x): void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/exponential_3.php
|
<?hh // strict
function takes_float(float $f): void { }
function test_ok(): void {
takes_float( 10.0 ** 2.0 );
takes_float( 10 ** 2.0 );
takes_float( 10.0 ** 2 );
}
function test_error(): void {
takes_float( 10 ** 2 );
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/expr_dep_force_solve.php
|
<?hh
function apply<T1, T2>((function(T1, T2): T1) $f, T1 $v1, T2 $v2): T1 {
return $f($v1, $v2);
}
interface C {
public function foo(C $other): C;
}
function test(C $value): void {
// Here we don't want the call $a->foo(...) to force
// solve T1 to (<expr#1> as C), or else the call will
// not typecheck.
apply(($a, $b) ==> $a->foo($b), $value, $value);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/expr_dep_nullable_bound.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class Box<T> {
public function __construct(private T $item) {}
public function set(T $x): void { $this->item = $x;}
public function get(): T { return $this->item; }
}
class C {
public function foo(): void { }
}
function foo(?C $oc): void {
$b = new Box($oc);
$b->get()?->foo();
$b->set(null);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/expr_dep_sub_option.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class C {
public function get(): this {
return $this;
}
public function set(?this $_): void {}
}
function test(C $c): void {
$d = $c->get();
$d->set($d);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/extend_generic.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 A {}
class B extends A {}
class C<T as A> {
}
class D<T as B> extends C<T> {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/extend_with_no_return.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 {
public function foo(): void {}
}
class B extends A {
public function foo() {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/extend_with_no_return2.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.
*
*
*/
interface A {
public function foo(): void;
}
interface B extends A {
public function foo();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/extend_with_no_return3.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.
*
*
*/
interface A {
public function foo(): void;
}
class B implements A {
public function foo() {}
}
|
Shell Script
|
hhvm/hphp/hack/test/typecheck/extracted_from_manual_updated.sh
|
#!/bin/bash
hack_manual_bin=$1
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
$hack_manual_bin extract "$SCRIPT_DIR/../../manual/hack"
CHANGED_FILES="$(hg st | grep extracted_from_manual/ )"
if [[ -z "$CHANGED_FILES" ]]
then
echo "No files changed!"
else
echo ""
echo "ERROR: Files have changed!"
echo "$CHANGED_FILES"
echo ""
echo "Please run the following command in your fbcode directory:"
echo "$ buck run fbcode//hphp/hack/src/hh_manual:hh_manual extract hphp/hack/manual/hack/"
echo "and amend the generated files into your diff."
exit 1
fi
|
PHP
|
hhvm/hphp/hack/test/typecheck/extra_scope.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 test(): void { }
}
function test(): void {
{ :foo::test(); }
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members1.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 X {
private static ?int $x = null;
public function getX(): int {
if(self::$x === null) {
self::$x = 0;
}
return self::$x;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members10.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 Foo1 {
public function frob(): void {
}
}
class Bar1 {
private ?Foo1 $foo;
public function __construct(?Foo1 $foo) {
$this->foo = $foo;
}
public function f(): void {
if ($this->foo) {
random_other_function();
$this->foo->frob();
}
}
}
function random_other_function(): void {
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members11.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 Bar1 {
private ?Vector<int> $foo;
public function __construct(?Vector<int> $foo) {
$this->foo = $foo;
}
public function f(): void {
if ($this->foo) {
random_other_function();
$this->foo[0] = 0;
}
}
}
function random_other_function(): void {
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members12.php
|
<?hh
function bar(): void {}
function baz(int $x): void {}
class Foo {
public ?int $x;
public function f(bool $y): void {
if ($this->x === null) {
return;
}
$y ? bar() : null;
// function call bar() invalidates info about $this->x
baz($this->x);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members13.php
|
<?hh //strict
class C {}
class D extends C {}
class Test {
public C $c;
public function __construct() {
//UNSAFE
}
}
function test(Test $t): void {
if ($t->c is D) {
take_string($t->c);
}
}
function take_string(string $s): void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members14.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class C {
public static ?int $fld = 42;
}
function foo((function():void) $f):void {
C::$fld = null;
$f();
}
function expect_int(int $x):void { }
<<__EntryPoint>>
function testit():void {
if (C::$fld !== null) {
foo(() ==> expect_int(C::$fld));
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.