language
stringlengths 0
24
| filename
stringlengths 9
214
| code
stringlengths 99
9.93M
|
---|---|---|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members2.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(X::$x === null) {
X::$x = 0;
}
return X::$x;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members3.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 do_something(): void {}
class X {
private static ?int $x = null;
public function getX(): int {
if (X::$x === null) {
X::$x = 0;
}
do_something();
return X::$x;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members4.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 do_something(): void {
}
class X {
private ?int $x;
public function getX(): int {
if($this->x === null) {
$this->x = 0;
}
do_something();
hh_show($this->x);
return $this->x;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members5.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 do_something(): void {
}
class X {
private mixed $x;
public function __construct() {
$this->x = '';
}
public function getX(): int {
if($this->x is int) {
return $this->x;
}
return 0;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members6.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 do_something(): void {
}
class X {
private mixed $x;
public function __construct() {
$this->x = '';
}
public function getX(): int {
if($this->x is int) {
do_something();
return $this->x;
}
return 0;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members7.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 do_something(): void {
}
class X {
private mixed $x;
public function __construct() {
$this->x = '';
}
public function getX(): Z {
if($this->x is Z) {
return $this->x;
}
return new Z();
}
}
class Z {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members8.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 do_something(): void {
}
class X {
private mixed $x;
public function __construct() {
$this->x = '';
}
public function getX(): Z {
if($this->x is Z) {
do_something();
return $this->x;
}
return new Z();
}
}
class Z {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_members9.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 show<T>(T $x): void {}
interface I { }
class A implements I { }
class B implements I { }
class Z {
public static async function genNotFoo(): Awaitable<void> {
return;
}
}
class Unrelated {
public I $foo;
public function __construct(I $foo) {
$this->foo = $foo;
}
public async function genFooAsA(): Awaitable<A> {
if (!($this->foo is A)) {
$this->foo = new A();
}
await Z::genNotFoo();
return $this->foo;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_nullable.php
|
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.
function darray_filter_falsy<Tk as arraykey, Tv as nonnull>(
KeyedTraversable<Tk, ?Tv> $traversable,
): darray<Tk, Tv> {
return darray[];
}
async function genak<Tk as arraykey, Tv>(
(function (Tk): Awaitable<Tv>) $gen,
Traversable<Tk> $keys,
): Awaitable<darray<Tk, Tv>> {
return darray[];
}
interface I { }
function tany() /* : TAny */ {
return null;
}
async function gennull():Awaitable<?I> {
return null;
}
class C {
private darray<arraykey,mixed> $fld = darray[];
public async function foo(): Awaitable<void> {
$this->fld = await genak<_,_>(
async (int $id) : Awaitable<?I> ==> await gennull(),
tany(),
);
$x = darray_filter_falsy<int,_>($this->fld);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fake_nullable2.php
|
<?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class C {
public function __construct(public ?Vector<int> $vec) { }
}
function testit(C $x):void {
$x->vec = Vector { };
for ($i = 0; $i < 10; $i++) {
$x->vec->add($i);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fallthrough_not_last_line.php
|
<?hh
function foo(int $x): void {
switch ($x) {
case 1: // FALLTHROUGH
3;
case 2:
case 3:
break;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fallthrough_out_of_switch.php
|
<?hh
// We currently parse FALLTHROUGH comments as Fallthrough statements only
// within switch statements, if we parsed them as Fallthrough statements
// indiscriminately and treat them in the typechecker as we do today (by
// moving the Next continuation to Fallthrough continuation), the following
// program would fail. This test makes sure we catch this if such a change is
// ever made.
function ko(int $x): void {
// FALLTHROUGH
hh_expect<int>($x);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_1.php
|
<?hh // strict
enum Foo: int as int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
/*
enum Bar: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
function test(): Foo {
return Foo::FOO;
}
function test2(int $x): void {}
function test3(): void {
test2(Foo::BAR);
}
function test4(): string {
echo 'foo'.Foo::BAR;
return Bar::FOO.Bar::BAZ;
}
function do_case(Bar $x): int {
switch ($x) {
case Bar::FOO:
return 0;
case Bar::BAR:
return 1;
case Bar::BAZ:
return 2;
}
return -1;
}
*/
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_10.php
|
<?hh // strict
enum Foo: int as int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
function getFooValues(): darray<string, Foo> {
return Foo::getValues();
}
function getFooValues2(): darray<string, int> {
return Foo::getValues();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_13.php
|
<?hh // strict
// No using HH\BuiltinEnum
function foo(mixed $foo): bool {
return $foo is HH\BuiltinEnum;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_14.php
|
<?hh
enum Foo: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
enum Bar: Foo as Foo {
FOO = Foo::FOO;
}
// Nullable enum supertype is still a supertype
function f(): ?Bar {
return Bar::FOO;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_17.php
|
<?hh // strict
enum Foo: int {
X = 1;
}
function f(): void {
$v = Foo::X;
$v::getValues();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_2.php
|
<?hh // strict
enum Foo: int as int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
// Foo can be used as int, but not the reverse
function test(): Foo {
return 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_3.php
|
<?hh // strict
// Should fail because no constraint
enum Foo: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
function test(): Foo {
return Foo::FOO;
}
function test2(int $x): void {}
function lurr(): void {
test2(Foo::BAR);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_6.php
|
<?hh // strict
// Should fail because string isn't a supertype of int
enum Foo: int as string {
FOO = 0;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_7.php
|
<?hh // strict
enum Bar: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
function test(): Bar {
return new Bar();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_8.php
|
<?hh // strict
enum Foo: int as int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
enum Bar: Foo as int {
FOO = Foo::FOO;
BAR = Foo::BAR;
}
function test(): Foo {
return Foo::FOO;
}
function test2(int $x): void {}
function test3(): void {
test2(Foo::BAR);
}
function do_case(Bar $x): int {
switch ($x) {
case Bar::FOO:
return 0;
case Bar::BAR:
return 1;
}
return -1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_9.php
|
<?hh // strict
enum Foo: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
function getFooValues(): darray<string, Foo> {
return Foo::getValues();
}
// This should fail.
function getFooValues2(): darray<string, int> {
return Foo::getValues();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_case_1.php
|
<?hh // strict
enum Bar: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
function do_case(Bar $x): int {
switch ($x) {
case Bar::FOO:
return 0;
case Bar::BAR:
return 1;
case Bar::BAZ:
return 2;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_case_11.php
|
<?hh // strict
enum MyEnum: string {
A = 'a';
B = 'b';
}
function f(MyEnum $e): void {
// Force to be Tvar/Tunion
if (true) {
$e = MyEnum::A;
}
switch ($e) {
case MyEnum::A: break;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_case_2.php
|
<?hh // strict
enum Bar: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
// Redundant match
function do_case(Bar $x): int {
switch ($x) {
case Bar::FOO:
return 0;
case Bar::BAR:
return 1;
case Bar::BAZ:
return 2;
case Bar::FOO:
return 3;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_case_3.php
|
<?hh // strict
enum Bar: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
// Non exhuastive match
function do_case(Bar $x): int {
switch ($x) {
case Bar::FOO:
return 0;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_case_4.php
|
<?hh // strict
// Make sure we block this trickiness:
enum Bar : int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
class Baz {
const Bar BAZ = Bar::FOO;
}
// Redundant match
function do_case(Bar $x): int {
switch ($x) {
case Bar::FOO:
return 0;
case Bar::BAR:
return 1;
// Bogus!
case Baz::BAZ:
return 2;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_case_5.php
|
<?hh // strict
enum Bar: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
function do_case(Bar $x): int {
switch ($x) {
case Bar::FOO:
return 0;
case Bar::BAR:
return 1;
case Bar::BAZ:
return 2;
default:
return 3;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_case_6.php
|
<?hh // strict
enum Bar: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
function do_case(Bar $x): int {
$z = Bar::FOO;
switch ($x) {
case $z:
return 0;
case Bar::BAR:
return 1;
case Bar::BAZ:
return 2;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_case_7.php
|
<?hh // strict
enum Bar: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
function do_case(Bar $x): int {
switch ($x) {
case Bar::FOO:
return 0;
case Bar::BAR:
return 1;
default:
return 2;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_case_9.php
|
<?hh
enum Bar: int {
FOO = 1;
BAR = 2;
BAZ = 3;
}
type Foo = Bar;
// We can make it through typedefs
function do_case(Foo $x): int {
switch ($x) {
case Bar::FOO:
return 0;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_classname.php
|
<?hh // strict
class Foo {
public static function x(): void {}
}
class Bar extends Foo {}
enum E: classname<Foo> as classname<Foo> {
FOO = Foo::class;
Bar = Bar::class;
}
function f(): void {
$cls = E::FOO;
$cls::x();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_implicitly_arraykey.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum FooInt: int {
FOO_VALUE_ONE = 1;
FOO_VALUE_TWO = 2;
}
enum FooStr: string {
FOO_VALUE_BAR = 'foobar';
FOO_VALUE_BAZ = 'foobaz';
}
enum BarInt: int as int {
BAR_VALUE_ONE = 1;
BAR_VALUE_TWO = 2;
}
enum BarStr: string as string {
BAR_VALUE_BAR = 'barbar';
BAR_VALUE_BAZ = 'barbaz';
}
function takes_arraykey(arraykey $arg): void {
// do nada
}
function main(): void {
// ensure opaque enum's values pass arraykey typehint
takes_arraykey(FooInt::FOO_VALUE_ONE);
takes_arraykey(FooStr::FOO_VALUE_BAR);
// ensure constrained enum's values pass arraykey typehint
takes_arraykey(BarInt::BAR_VALUE_ONE);
takes_arraykey(BarStr::BAR_VALUE_BAR);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fc_enum_non_arraykey_constraint.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum Enum: string as ?string {
VALUE = 'value';
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/finally_basic.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 finally_basic(): int {
$a = 23;
try {
$a = 456;
} catch (NonTerminalException $e) {
$a = 28;
} catch (SomeException $e) {
return $a == 23;
} catch (Exception $e) {
return $a == 456;
} finally {
echo $a;
$b = 'quack'; // should be fine (!)
echo $b;
}
return $a;
}
function do_something(): void {
throw new Exception('something like throwing :)');
}
class TestInit {
private int $foo;
public function __construct() {
try {
do_something();
$this->foo = 26;
} finally {
$this->foo = 25;
}
}
}
class NonTerminalException extends Exception {}
class SomeException extends Exception {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/finally_naming.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 might_throw(): void {}
function naming_finally(): int {
$a = 23;
try {
$a = 456;
might_throw();
$b = 789;
} catch (YourException $e) {
return $b == 23;
} catch (Exception $e) {
return $a == 456;
} finally {
echo $b; // b is unknown!
}
return $a;
}
class YourException extends Exception {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/finally_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.
*
*
*/
function f(): int {
try {
return 42;
} finally {
$x = () ==> {
return 24;
};
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/finally_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.
*
*
*/
function finally_return_error(): int {
try {
return 42;
} finally {
return 24;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/finally_typing.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 finally_typing1(): string {
$a = 23;
try {
do_something();
} finally {
$a = 'string'; // this definition escapes the clause
}
return $a;
}
function finally_typing2(): string {
$a = 23;
try {
do_something();
return 'string';
} finally {
// this definition escapes the clause, even with terminality
$a = 'string';
}
return $a;
}
// with a different story with respect to unreachable code ...
// function finally_typing3(): int {
// $a = 23;
// try {
// do_something();
// $a = 25;
// return $a; // terminal block
// } finally {
// // this assignment beats out the original, but it doesn't matter
// // because the try is fully terminal
// $a = 'string';
// }
// return $a;
// }
function do_something(): void {}
function finally_typing3(bool $c): int {
try {
try {
if ($c) {
$a = "string";
throw new Exception();
}
$a = 0;
} finally {
// $a has different types depending on the continuation
$b = $a;
}
} catch (Exception $_) {
// $b should be a string here
return str_to_int($b);
}
return $b;
}
function str_to_int(string $s): int {
return 0;
}
function finally_typing4(int $x): void {
$a = 0;
try {
try {
if ($x < 0) {
throw new Exception();
}
} finally {
if ($x < 1) {
$a = "string";
throw new Exception();
}
$a = 1;
}
} catch (Exception $_) {
hh_show($a);
return;
}
hh_show($a);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/finally_tyvars.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
async function gen_empty_shape(): Awaitable<shape()> {
return shape();
}
async function test(): Awaitable<void> {
try {
throw new Exception();
} catch (Exception $_) {
} finally {
$s = await gen_empty_shape();
Shapes::idx($s, 'foo');
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/final_abstract.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.
*
*
*/
final abstract class FinalAbstractTest {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/final_class.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
<<__Sealed()>>
final class A {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/final_final1.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.
*
*
*/
final final class FinalFinalTest {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/final_final2.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.
*
*
*/
final final abstract class FinalFinalTest {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/final_final3.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.
*
*
*/
final abstract final class FinalFinalTest {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/final_final4.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.
*
*
*/
abstract final final class FinalFinalTest {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/final_private_trait.php
|
<?hh
trait MyTrait {
public function foo(): void { $this->bar(); }
final private function bar(): void {}
}
class MyClass {
use MyTrait;
private function bar(): void {} // should error, clobbering trait internals
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/final_property.php
|
<?hh // strict
class A {
private final int $value1, $value2;
public final int $value3;
private int $value4;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fixme_cascade.php
|
//// a.php
<?hh
function foo(
/* HH_FIXME[4110] */
int $i
): void {}
//// b.php
<?hh
function test(): void {
foo('h');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/fold_plus.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 test(): void {
$x = Vector {};
$x[] = 0;
$x[] = 0.0;
$y = $x[0] - 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/for.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 f1(): void {
for ($i=0, $j=0; $i<10; $i++, $j++) {
echo $i, "\t", $j, "\n";
}
}
function f2(): void {
for ($i=0;$i<10;) {
}
}
function f3(): void {
$i = 0;
for (; $i<0;){
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/forbid_await_in_sync_functions1.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 bar(Awaitable<string> $x): void {
print(await $x);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/forbid_await_in_sync_functions2.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 Titan {
private async function eren(): Awaitable<void> {
return;
}
public function miracle(): void {
await $this->eren();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/forbid_await_in_sync_functions3.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 sjm() {
return function(Awaitable<mixed> $the_doctor) {
await $the_doctor;
};
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/forbid_await_in_sync_functions4.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 char_select(
Awaitable<int> $fireboy,
Awaitable<string> $watergirl,
): Awaitable<int> {
return await $fireboy;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/forbid_await_in_sync_functions5.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 char_select(
Awaitable<int> $fireboy,
Awaitable<Exception> $watergirl,
): void {
throw await $watergirl;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_anyarray_and_dynamic.php
|
<?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
function testforeach2(dynamic $d):void {
if (HH\is_any_array($d)) {
foreach ($d as $y) {
$x = $y[0];
}
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_bad_lvalue.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 f(): void {
foreach (varray[1] as 42) {
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_break.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 f(): void {
foreach (varray[1] as $k => $v) {
break;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_kv_bad_lvalue.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 f(): void {
foreach (varray[1] as $k => 42) {
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_kv_list.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 takes_int(int $a): void {}
function takes_string(string $a): void {}
function foo(): varray<(int, string)> {
return varray[];
}
function f(): void {
foreach (foo() as $k => list($x, $y)) {
takes_int($x);
takes_string($y);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_kv_list2.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(string $x): void {}
function test(): void {
$arr = varray[varray[1, 2], varray[3, 4]];
foreach ($arr as $k => list($x, $y)) {
foo($x);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_kv_list_async.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 takes_int(int $a): void {}
function takes_string(string $a): void {}
async function bar(): AsyncKeyedIterator<int, (int, string)> {
yield 1 => tuple(1, "a");
}
async function test(): Awaitable<void> {
foreach (bar() await as $k => list($x, $y)) {
takes_int($x);
takes_string($y);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_kv_list_async2.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(string $x): void {}
async function bar(): AsyncKeyedIterator<int, (int, int)> {
yield 1 => tuple(1, 1);
}
async function test(): Awaitable<void> {
foreach (bar() await as $k => list($x, $y)) {
foo($x);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_list.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 takes_int(int $a): void {}
function takes_string(string $a): void {}
function foo(): varray<(int, string)> {
return varray[];
}
function test(): void {
foreach (foo() as list($x, $y)) {
takes_int($x);
takes_string($y);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_list2.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(string $x): void {}
function test(): void {
$arr = varray[varray[1, 2], varray[3, 4]];
foreach ($arr as list($x, $y)) {
foo($x);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_list_async.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 takes_int(int $a): void {}
function takes_string(string $a): void {}
async function bar(): AsyncIterator<(int, string)> {
yield tuple(1, "a");
}
async function test(): Awaitable<void> {
foreach (bar() await as list($x, $y)) {
takes_int($x);
takes_string($y);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_list_async2.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(string $x): void {}
async function bar(): AsyncIterator<(int, int)> {
yield tuple(1, 1);
}
async function test(): Awaitable<void> {
foreach (bar() await as list($x, $y)) {
foo($x);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_local.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(Map<string, Map<string, int>> $map): void {
foreach ($map as $m) {
$m = $m[''];
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_nonnull.php
|
<?hh
function foo(vec<int> $v): void {
$w = Vector{null, $v};
$x = $w[0];
if ($x !== null) {
foreach ($x as $y) {}
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_over_unresolved_key.php
|
<?hh // strict
function expect_arraykey(arraykey $_): void {}
function test(bool $b, dict<string, string> $x, dict<int, string> $y): void {
if ($b) {
$z = $x;
} else {
$z = $y;
}
foreach ($z as $k => $_) {
expect_arraykey($k);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_over_unresolved_value.php
|
<?hh // strict
function expect_arraykey(arraykey $_): void {}
function test(bool $b, vec<string> $x, vec<int> $y): void {
if ($b) {
$z = $x;
} else {
$z = $y;
}
foreach ($z as $v) {
expect_arraykey($v);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_scoping.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 test_func(): int {
$var = null;
foreach (varray[] as $_) {
$var = 1;
}
return $var; // this should be type `int & ?_`, but hack thinks it's `int`
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_union_dynamic.php
|
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.
function doit(dynamic $d, bool $p):void {
if ($p) {
$d = $p;
}
foreach($d as $e) {
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/foreach_vector.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 bar(): void {}
}
function f(Vector<Foo> $v): void {
foreach ($v as $foo) {
$foo->bar();
$x = $foo + 5;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/for_break.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 f(): void {
for ($i=0; $i<10; ++$i) {
if ($i > 5) {
break;
}
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/for_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_for(int $i): void {
$x = $i;
for( ; $x = true; $i++) {
$i += $x;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/for_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.
*
*
*/
class A {}
function myFunc(): A {
$var = null;
// Hack assumes that this loop might or might not run.
for ($i = 0; $i < 1; $i++) {
$var = new A();
}
return $var;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/for_loop_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.
*
*
*/
function foo(?string $x): string {
$x = 'hello';
while ($x == 'hello') {
$x = 'goodbye';
}
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/for_multiexpression_condition_with_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_for(int $i): void {
$x = $i;
for( ; $x = 1, $x = "hello"; $i++) {
$i %= $x;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/for_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(?int $i): void {
for( ; $i !== null; $i = null) {
$i = $i + 5;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/funcall_explicit_arg.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function foo<T1, T2>(T1 $x) : T1 {
return $x;
}
function bar() : int {
return foo<int, string>(5);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/funcall_explicit_arg_arity_error.php
|
<?hh // strict
function foo<T1, T2>(T1 $x) : T1 {
return $x;
}
function bar() : int {
return foo<int>(5);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/funcall_explicit_arg_error.php
|
<?hh // strict
function foo<T1, T2>(T1 $x) : T1 {
return $x;
}
function bar() : int {
return foo<int, string>("Hi");
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/funcall_explicit_arg_infer.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function id<T>(T $x): T {
return $x;
}
function inferID(int $x): int {
return id<_>($x);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/funcall_explicit_arg_infer_error.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function id<T>(T $x): T { return $x; }
function infer_and_error(int $x): string {
return id<_>($x);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_anon_fun.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 {
public function doStuff(): void {
return;
}
}
function f(int $x): int {
$f = function($y) use ($x) {
return $y->doStuff();
};
$result = ($f)(new A());
return $result;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_box.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 Box<T> {
private T $x;
public function __construct(T $x) {
$this->x = $x;
}
public function set(T $x): void {
$this->x = $x;
}
public function get(): T {
return $this->x;
}
}
class Ent {}
class EntUser extends Ent {
public function iAmUser(): void {
return;
}
}
class EntPhoto extends Ent {}
class BoxEnt extends Box<Ent> {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_dots.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 f((function(int, float...): string) $g): string {
return $g(5, 23.3);
}
<<__EntryPoint>>
function test(): void {
// Should not accept this!
f(
function(int $x, string $y, float ...$args): string {
return $x."<-";
},
);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_dots2.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 f((function(int, string, mixed...): string) $g): string {
return $g(5, 'five');
}
function test(): void {
f(
function(int $x, mixed ...$args): string {
return $x."<-";
},
);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_dots3.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 {}
function f((function(B, mixed...): string) $g): string {
return $g(new B(), 5);
}
function test(): void {
f(
function(A $x, mixed ...$args): string {
return "...";
},
);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_dots4.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 {}
function f((function(B, mixed...): string) $g): string {
return $g(new B());
}
function test(): void {
f(
function(A $x, mixed ...$args): string {
return "...";
},
);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_dots5.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 {}
function f((function(B, mixed...): string) $g): string {
return $g(new B());
}
function test(): void {
f(
function(A $x, mixed ...$y): string {
return "...";
},
);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_generator.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 Stream<T> {}
async function g(): Awaitable<bool> {
return false;
}
async function f(): Awaitable<int> {
$x = await g();
if ($x) {
return 1;
} else {
return 2;
}
}
function intgen(): Stream<int> {
yield 1;
yield 2;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_higher_order.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 f<T>((function(T): T) $g, T $x): T {
return ($g)($x);
}
function test(): void {
f(
function($x) {
return $x + 1.0;
},
0,
);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_higher_order2.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 build<T>(T $x): (function(T): T) {
return function(T $y): T use ($x) {
return $y;
};
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_locals.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 {
if (false) {
$x = 44;
}
if (true) {
$x = 0;
} else {
$x = 1;
}
return 0;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_option.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 extends Exception {}
function f(?int $x): int {
if (is_null($x)) {
throw (new A());
}
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/functional_toposort.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 extends B {}
class B extends A {}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.