language
stringlengths 0
24
| filename
stringlengths 9
214
| code
stringlengths 99
9.93M
|
---|---|---|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_33.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.
*
*
*/
/**
* Hack treats method dispatch in a different way from PHP.
*/
class A {
public function f1(): void {}
public static function f2(): void {}
}
class B extends A {
public function f1(): void {}
public static function f2(): void {}
public function test1(): void {
$this->f1();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_34.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.
*
*
*/
/**
* Hack treats method dispatch in a different way from PHP.
*/
class A {
public function f1(): void {}
public static function f2(): void {}
}
class B extends A {
public function f1(): void {}
public static function f2(): void {}
public function test1(): void {
$this::f1();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_35.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.
*
*
*/
/**
* Hack treats method dispatch in a different way from PHP.
*/
class A {
public function f1(): void {}
public static function f2(): void {}
}
class B extends A {
public function f1(): void {}
public static function f2(): void {}
public function test1(A $x): void {
$x->f1();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_36.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.
*
*
*/
/**
* Hack treats method dispatch in a different way from PHP.
*/
class A {
public function f1(): void {}
public static function f2(): void {}
}
class B extends A {
public function f1(): void {}
public static function f2(): void {}
public function test1(A $x): void {
$x::f1();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_37.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.
*
*
*/
/**
* Hack treats method dispatch in a different way from PHP.
*/
class A {
public function f1(): void {}
public static function f2(): void {}
}
class B extends A {
public function f1(): void {}
public static function f2(): void {}
public function test1(A $x): void {
/* HH_FIXME[4090] */
$x::f1();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_subtyping_new.php
|
<?hh // strict
class Foo {
public function qq(int $x): num {
return 5;
}
}
interface I {
public function qq(int $x): num;
}
class Bar extends Foo implements I {
public function qq(num $x): int {
return 4;
}
}
abstract class AbstractFoo {
abstract public function qq(int $x): num;
}
class AbstractBar extends AbstractFoo {
public function qq(num $x): int {
return 5;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller1.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 {
public function foo(): void {}
}
function test1(): (function(X): void) {
return meth_caller('X', 'foo');
}
function test2(): (function(X): void) {
return meth_caller(X::class, 'foo');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller10.php
|
<?hh // strict
class X<T> {
public function foo(T $x): T {
return $x;
}
}
function test(): X<int> {
$caller = meth_caller('X', 'foo');
$x = new X();
$caller($x, 'a string');
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller11.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 function bar(): void {
echo 'bar';
}
}
class Wrapper<T> {
public function __construct(private T $item) {}
public function foo(): T {
return $this->item;
}
}
function use_with_ints((function(Wrapper<int>): C) $caller): void {
$b = $caller(new Wrapper(3));
$b->bar();
}
function breakIt(): void {
$caller = meth_caller('Wrapper', 'foo');
use_with_ints($caller);
}
function main(): void {
breakIt();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller2.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 {
public function foo(): void {}
}
function test(): (function(X): int) {
return meth_caller(X::class, 'foo');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller3.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<T> {
public function foo(T $x): T { return $x; }
}
function test1(): (function(X<int>, int): int) {
return meth_caller('X', 'foo');
}
function test2(): (function(X<int>, int): int) {
return meth_caller(X::class, 'foo');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller4.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<T> {
public function foo(T $x): T {
return $x;
}
}
function use_with_ints((function(X<int>, int): int) $caller): void {}
function test(): (function(X<bool>, bool): bool) {
$caller = meth_caller('X', 'foo');
use_with_ints($caller);
return $caller;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller6.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 class E {
public function foo(): void {}
}
final class A<T as E> {
public function __construct((function(T): void) $x) {}
}
function test1<T as E>(): A<T> {
return new A(meth_caller('E', 'foo'));
}
function test2<T as E>(): A<T> {
// Type of $f should be
// function(E):void
$f = meth_caller(E::class, 'foo');
// Now type of $r should be
// A<x>
// with constraint that
// x <: E
// function(E):void <: function(x):void
// i.e.
// x <: E (contravariance), so we're ok
$r = new A($f);
// Now we need to check the return type
// A<x> <: A<T>
// So by invariance we have x=T, and we're ok
// because of the T as E constraint
return $r;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller7.php
|
<?hh // strict
class C {
public function foo2(int $x, string $y): void {}
}
function test(C $c): void {
$caller = meth_caller(C::class, 'foo2');
$caller($c, '', 0);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller8.php
|
<?hh // strict
class C {
public function foo2(int $x, string $y): void {}
}
function test(C $c): void {
$caller = meth_caller(C::class, 'foo2');
$caller($c, 0);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller9.php
|
<?hh // strict
class C {
public function var_args(int ...$x): void {}
}
function test(C $c): void {
$caller = meth_caller(C::class, 'var_args');
$caller($c);
$caller($c, 1);
$args = Vector { 1, 2, 3 };
$caller($c, ...$args);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller_inout1.php
|
<?hh
class Foo {
public function bar(inout int $_): void {}
}
function test(): void {
$x = HH\meth_caller('Foo', 'bar');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller_inout2.php
|
<?hh
class Foo {
public function bar(string $_, inout int $_): void {}
}
function test(): void {
$x = HH\meth_caller('Foo', 'bar');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/meth_caller_magic.php
|
<?hh
class Foo {
public function __construct() {}
}
function test(): void {
HH\meth_caller(Foo::class, '__construct');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/missing_const_typehint.php
|
<?hh // strict
class C {
const X = 123; // This is OK; it's clear what the type is.
const int Y = self::X; // This is OK.
const Z = self::X; // This is not OK.
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/missing_generic.php
|
<?hh
class A {}
class B {}
class C<T> extends B {}
class D<T> extends C<T> {}
class E<T> extends C<int> {}
interface I<T> {
require extends C<int>;
}
interface J<T> {
require extends C<T>;
}
/* HH_FIXME[4101] */
function f(C $x) : B {
return $x; // OK
}
/* HH_FIXME[4101] */
function g(B $x) : C {
return $x; // ERROR
}
/* HH_FIXME[4101] */
function h(C $x) : C<int> {
return $x; // ERROR
}
/* HH_FIXME[4101] */
function i(C<int> $x) : C {
return $x; // OK
}
/* HH_FIXME[4101] */
function j(C $x) : A {
return $x; // ERROR
}
/* HH_FIXME[4101] */
function k(A $x) : C {
return $x; // ERROR
}
/* HH_FIXME[4101] */
function l(D $x) : C<int> {
return $x; // ERROR
}
/* HH_FIXME[4101] */
function m(E $x) : C<int> {
return $x; // OK
}
/* HH_FIXME[4101] */
function n(E<int> $x) : C {
return $x; // OK
}
/* HH_FIXME[4101] */
function o(D<int> $x) : C {
return $x; // OK
}
/* HH_FIXME[4101] */
function p(I $x) : C<int> {
return $x; // OK
}
/* HH_FIXME[4101] */
function q(J $x) : C<int> {
return $x; // ERROR
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/missing_tparam.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> {
private T $x;
public function __construct(T $x) {
$this->x = $x;
}
public function get(): T {
return $this->x;
}
}
/* HH_FIXME[4101] */
function foo(A $x): int {
return $x->get();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/missing_tparam2.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<T> {
private T $x;
public function __construct(T $x) { $this->x = $x; }
public function get(): T {return $this->x;}
}
function foo(A $x): int {
return $x->get();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/missing_tparam3.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> {
private T $x;
public function __construct(T $x) {
$this->x = $x;
}
public function get(): T {
return $this->x;
}
}
class B extends A {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/mixed_instanceof.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(): mixed {
return 0;
}
function test(bool $statement): bool {
if(!$statement) {
$y = foo();
invariant($y is Exception, "");
throw $y;
}
return $statement;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/mixed_lambda_explicit_return_ko.php
|
<?hh
class C {
public function __construct(
public mixed $f,
) {}
}
function f(): void {
new C(($x) : int ==> $x);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/mixed_lambda_ko.php
|
<?hh
class C {
public function __construct(
public mixed $f,
) {}
}
function f(): void {
new C($x ==> $x + 1);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/mixed_lambda_ok.php
|
<?hh
class C {
public function __construct(
public mixed $f,
) {}
}
function f(): void {
new C($x ==> $x);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/mixed_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(mixed $bar = null): void {
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/mixed_null2.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(mixed $bar): void {}
function bar(): void {
foo(null);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/mixed_obj_init.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 MixedInitTest {
protected mixed $foo;
public function __construct() {
// make sure we are allowed to call functions
$this->something();
}
protected function something(): void {
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/mixed_option.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.
*
*
*/
async function f(): Awaitable<?mixed> {
return null;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/mixed_subtype.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class Foo {
public function A(): nothing {
throw new Exception();
}
}
class Bar extends Foo {
public function A(): mixed {
throw new Exception();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/multi.php
|
<?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
function expectTwo(int $x, bool $y):void { }
function expectPair((int,bool) $p):void { }
function expectShape(shape('a' => int, 'b' => bool, 'c' => string) $s):void { }
function testThem():void {
expectTwo("A", 2.3);
expectPair(tuple("A", 2.3));
expectShape(shape('a' => "A", 'b' => 2.3));
$s = shape('a' => "C", 'b' => 4.5);
expectShape($s);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/multiple_concrete_consts.php
|
<?hh
interface I1 {
const int X = 7;
}
interface I2 {
const int X = 5;
}
interface I extends I1, I2 {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/multiple_concrete_consts2.php
|
<?hh
interface I1 {
abstract const int X;
}
interface I2 {
const int X = 5;
}
interface I extends I1, I2 {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/multiple_concrete_defs_from_traits.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
trait T1 {
public static num $p = 5.4;
}
trait T2 {
public static num $p = 5.0;
}
trait T3 {
public static num $p = 4;
}
class C {
use T1, T2, T3;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/multiple_concrete_defs_from_traits_no_default.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
trait T1 {
private ?int $tutorialID;
}
trait T2 {
private ?int $tutorialID;
}
class C {
use T1, T2;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/multiple_traits_require_implements.php
|
<?hh
interface I {
public function foo(int $_): void;
}
interface J {
public function foo(string $_): void;
}
trait T1 {
require implements I;
}
trait T2 {
require implements J;
}
trait T {
use T1;
use T2;
public function bar(): void {
$this->foo("");
}
}
class A implements J, I {
use T;
public function foo(int $_): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/multi_assign.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(): (int, int) {
if (true) {
$x = 0;
$y = 1;
} else {
$x = $y = 1;
}
return tuple($x, $y);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/multi_bracket.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 {
{
{
}
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/multi_gen.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<T> {}
function foo<T, T2 as A<T>>(T2 $x): void {
}
function test(A<int> $a): void {
foo($a);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/mul_union.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function badInt(bool $b): int {
if ($b) {
$x = 3;
} else {
$x = 3.4;
}
$z = 3 * $x;
if ($z is int) {
echo 'int';
} else {
echo 'not int';
}
return $z;
}
function main(): void {
badInt(false);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespaced_classname.php
|
<?hh // strict
namespace foo\bar;
<<__ConsistentConstruct>>
class Herp {}
class Derp extends Herp {}
function foo<T as Herp>(classname<T> $class): T {
return new $class();
}
function bar(Vector<string> $foo): void {}
function main(): void {
foo(Derp::class);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_async_1.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.
*
*
*/
namespace NS1;
async function f(): Awaitable<void> {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_async_2.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.
*
*
*/
namespace NS1;
//use \HH\Awaitable;
async function f(): Awaitable<void> {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_basic.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.
*
*
*/
namespace NS1\NS2 {
trait MyTrait<T1, T2> {}
function f(): void {
f();
\NS1\NS2\f();
}
class C<T> {
use MyTrait<T, int>;
public static function g(): void {
C::g();
\NS1\NS2\C::g();
}
public function h(): void {
$this->h();
}
public function i(C<T> $x): \NS1\NS2\C<T> {
return $x;
}
}
function id<T>(T $x): T {
return $x;
}
function id2<T as C<int>>(T $x): T {
return $x;
}
function id3<T as \NS1\NS2\C<int>>(T $x): T {
return $x;
}
}
namespace NS3 {
class C2 extends \NS1\NS2\C<int> {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_collections1.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.
*
*
*/
namespace N;
function f(): \Map<int, int> {
$m = \Map {};
return $m;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_collections2.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.
*
*
*/
namespace N;
function f(): Map<int, int> {
$m = \Map {};
return $m;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_collections3.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.
*
*
*/
namespace N;
function f(): \Map<int, int> {
$m = Map {};
return $m;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_collections4.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.
*
*
*/
namespace N;
function f(): Map<int, int> {
$m = Map {};
return $m;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_global_builtin1.php
|
<?hh // strict
namespace Test;
function f(): void {
invariant(true, 'hi');
}
function g(): void {
invariant_violation('hi');
}
function h(): void {
\Test\f<>;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_global_builtin2.php
|
<?hh // strict
namespace Test;
function invariant_violation(): int {
return 10;
}
function f(): string {
invariant_violation('auto-import');
}
function g(): int {
return \Test\invariant_violation();
}
interface Traversable<T> {}
// Refers to autoimported Traversable
class Vector implements Traversable<int> {}
function h(): Traversable<int> {
return new \Test\Vector();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_global_class1.php
|
//// global.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 {}
//// local.php
<?hh // strict
namespace N {
function f(): void {
new \C();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_global_class2.php
|
//// global.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 {}
//// local.php
<?hh // strict
namespace N {
function f(): void {
new C();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_global_const1.php
|
<?hh // strict
namespace {
const string MYCONST = 'hi test';
}
namespace N {
function f(): string {
return MYCONST;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_global_const2.php
|
<?hh // strict
namespace {
const string MYCONST = 'hi test';
}
namespace N {
const int MYCONST = 1;
function f(): string {
return MYCONST;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_global_function1.php
|
//// global.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 {}
//// local.php
<?hh // strict
namespace N {
function g(): void {
\f();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_global_function2.php
|
//// global.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 {}
//// local.php
<?hh // strict
namespace N {
function g(): void {
f();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_global_function3.php
|
//// global.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 {}
//// local.php
<?hh // strict
namespace N {
function g(): void {
NN\f();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_global_function4.php
|
//// global.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(): int {
return 42;
}
//// local.php
<?hh // strict
namespace N {
function f(): string {
return 'this one should be used';
}
function g(): string {
return f();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_global_qualified.php
|
//// N.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.
*
*
*/
namespace N {
class C {}
}
//// test.php
<?hh // strict
function f(N\C $x): \N\C {
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_group_use.php
|
<?hh // strict
namespace Foo\Bar\Baz {
function f1(): void {}
function f2(): void {}
const int CN = 1;
class CL {}
class CL2 {}
}
namespace X {
use Foo\Bar\Baz\{CL, function f1, const CN, CL2};
function f(): void {
new CL();
f1();
\var_dump(CN);
new CL2();
}
}
namespace X2 {
use function Foo\Bar\Baz\{f1, f2};
function f(): void {
f1();
f2();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_group_use_format.php
|
<?hh // strict
namespace TestFormatter {
use Some\Very\Long\Name\Space\{
Very\Long\Name\Number\One,
Very\Long\Name\Number\Two,
Very\Long\Name\Number\Three,
};
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_implements2.php
|
<?hh // strict
namespace T {
class A implements \Countable {
public function count(): int {
return 0;
}
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_infinite_loop1.php
|
<?hh
namespace libphonenumber{\/
class PhoneNumber{
}
class PhoneNumberUtil{
public static function getInstance():PhoneNumber;
public static function isValidNumber(PhoneNumber):bool
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_namespace1.php
|
<?hh // strict
namespace Foo {
function f(): int {
$x = namespace\Bar\g();
hh_show($x);
return $x;
}
}
namespace Foo\Bar {
function g(): int {
return 0;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_namespace2.php
|
<?hh // strict
namespace Foo {
function f(): string {
$x = namespace\Bar\g();
hh_show($x);
return $x;
}
}
namespace Foo\Bar {
function g(): int {
return 0;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_newtype.php
|
//// def.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.
*
*
*/
namespace N {
newtype Foo = int;
function bless(int $x): Foo {
return $x;
}
function bless2(int $x): \N\Foo {
return $x;
}
}
//// use1.php
<?hh
function f(int $x): \N\Foo {
return \N\bless($x);
}
//// use2.php
<?hh
namespace N {
function f(int $x): Foo {
return bless($x);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_qualified.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.
*
*
*/
namespace NS1\SubNS\SubSubNS {
class C {}
}
namespace NS1 {
function f(): void {
new SubNS\SubSubNS\C();
}
}
namespace NS1\SubNS {
function f(): void {
new SubSubNS\C();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_unscoped.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.
*
*
*/
namespace NS1;
function f(): void {
\NS2\f();
}
namespace NS2;
function f(): void {
\NS1\f();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_use.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.
*
*
*/
namespace NS1\SubNS1 {
class C {}
}
namespace NS2 {
use NS1 as X;
use NS1\SubNS1, NS1\SubNS1\C as Y;
use \NS1\SubNS1 as Z;
function f(): void {
new \NS1\SubNS1\C();
new X\SubNS1\C();
new SubNS1\C();
new Y();
new Z\C();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_use_call_function.php
|
<?hh // strict
namespace N\NN {
function f(): void {}
}
namespace N2 {
use N\NN;
function f(): void {
NN\f();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_use_function_const.php
|
<?hh // strict
namespace N {
function f(): void {
echo "hi\n";
}
const int C = 1;
}
namespace N2 {
use function N\f;
use const N\C as D;
function f2(): int {
f();
return D;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/namespace_use_outside_namespace.php
|
//// defn.php
<?hh // strict
namespace NSTest;
class C {}
//// usage.php
<?hh // strict
use NSTest\C;
function f(): void {
$a = new C();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_fail_test1.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.
*
*
*/
// testing that names existing on both sides of if is defined
function stmt(bool $b): void {
if ($b) {
$x = 0;
}
else {
}
$x += 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_fail_test3.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 might_throw(): void {}
// testing exception scoping
function stmt(): void {
try {
might_throw();
$x = 0;
throw new Exception('this is a test');
}
catch(Exception $e) {
}
$x += 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_fail_test4.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 might_throw(): void {}
// testing loops scoping
function stmt(): void {
try {
might_throw();
$x = 0;
throw new Exception('this is a test');
}
catch(Exception $e) {
}
$x += 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_fail_test6.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.
*
*
*/
// testing loops scoping
function stmt(): void {
while($i < 100) {
$i++;
}
$i+=1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_fail_test7.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.
*
*
*/
// testing loops scoping
function stmt(Vector<int> $x): void {
foreach($x as $k => $v) {
}
$k++;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_fail_test8.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.
*
*
*/
// testing loops scoping
function stmt(Vector<int> $x): void {
foreach($x as $k => $v) {
}
foreach($x as $k => $v) {
$k++;
}
$k++;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_fail_test9.php
|
<?hh
class FooException extends Exception {}
function f(): void {
try {
might_throw();
} catch (FooException $e) {
} catch (Exception $_) {
echo $e;
}
}
function might_throw(): void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_ok_test1.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.
*
*
*/
// testing that names existing on both sides of if is defined
function stmt(): void {
if (true) {
$x = 0;
} else {
$x = 1;
}
$x += 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_ok_test11.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(): void {
do {
$x = 0;
} while ($x < 100);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_ok_test12.php
|
<?hh // strict
const string X = '';
class X {}
function X(string $x): void {}
function test(): void {
X(X);
new X();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_ok_test2.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.
*
*
*/
// testing that names existing on both sides of if is defined
function stmt(): void {
switch (true) {
case true:
$x = 0;
break;
default:
$x = 1;
break;
}
$x += 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_ok_test3.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.
*
*
*/
// testing exception scoping
function stmt(): void {
try {
$x = 0;
throw new Exception('this is a test');
} catch (Exception $e) {
$x = 1;
}
$x += 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_ok_test4.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.
*
*
*/
// testing loops scoping
function stmt(): void {
try {
$x = 0;
throw new Exception('this is a test');
} catch (Exception $e) {
$x = 1;
}
$x += 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_ok_test5.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.
*
*
*/
// testing loops scoping
function stmt(): void {
for ($i = 0; $i < 100; $i++) {
}
$i += 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_ok_test6.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.
*
*
*/
// testing loops scoping
function stmt(): void {
$i = 0;
while ($i < 100) {
$i++;
}
$i += 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_ok_test7.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.
*
*
*/
// testing loops scoping
function stmt(Vector<int> $x): void {
foreach ($x as $k => $v) {
$k++;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_ok_test8.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.
*
*
*/
// testing loops scoping
function stmt(Vector<int> $x): void {
foreach ($x as $k => $v) {
$k++;
}
foreach ($x as $k => $v) {
$k++;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/naming_ok_test9.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.
*
*
*/
// testing loops scoping
function stmt(Vector<int> $x): void {
foreach ($x as $k => $v) {
}
foreach ($x as $k => $v) {
$k++;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/negative_class_consts.php
|
<?hh // strict
class C {
const FOO = -1;
const BAR = 0;
const BAZ = +1;
public function f(): void {
hh_show(C::FOO);
hh_show(C::BAR);
hh_show(C::BAZ);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/neg_enum.php
|
<?hh
enum Ei : int {
Ki = 1;
}
enum Es : string {
Ks = "1";
}
function expect_int(int $i) : void {}
function expect_string(string $i) : void {}
function expect_Es(Es $es) : void {}
function expect_Ei(Ei $ei) : void {}
function f(Es $es, Ei $ei, arraykey $ak) : void {
if ($es is int) {
expect_int($es);
expect_Es($es);
} else {
expect_string($es);
expect_Es($es);
}
if ($ei is int) {
expect_int($ei);
expect_Ei($ei);
} else {
expect_string($ei);
expect_Ei($ei);
}
if ($ak is int) {
expect_int($ak);
} else {
expect_string($ak);
}
}
function g(Es $es, Ei $ei, arraykey $ak) : void {
if ($es is string) {
expect_string($es);
expect_Es($es);
} else {
expect_int($es);
expect_Es($es);
}
if ($ei is string) {
expect_string($ei);
expect_Ei($ei);
} else {
expect_int($ei);
expect_Ei($ei);
}
if ($ak is string) {
expect_string($ak);
} else {
expect_int($ak);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/nested_function_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(): (function (): void) {
while (true) {
return function () {
break;
};
} // FIXME(coeffects) below should be also OK without [defaults]
return function ()[defaults] {};
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/nested_shapes_idx.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
type Shape = shape(?'x' => ?shape('y' => int));
function test(Shape $s): void {
Shapes::idx(
Shapes::idx($s, 'x', shape()),
'y',
0,
);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/nested_shapes_idx_hh_fixme.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
type Shape = shape(?'x' => ?shape('y' => int));
function test(Shape $s): void {
Shapes::idx(
/* HH_FIXME[4110] */ /* HH_FIXME[4323] */
Shapes::idx($s, 'x', shape()),
'y',
0,
);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/newctx_super.php
|
////file1.php
<?hh
<<file: __EnableUnstableFeatures('context_alias_declaration_short')>>
newctx MyContext as [];
newctx MyContextSuper as [] super [defaults];
////file2.php
<?hh
class Foo {
public function f()[defaults]: void {} // explicit defaults for clarity
}
class Bar extends Foo {
public function f()[MyContextSuper]: void {}
}
class Bad extends Foo {
public function f()[MyContext]: void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/newctx_super_closure.php
|
////file1.php
<?hh
<<file: __EnableUnstableFeatures('context_alias_declaration_short')>>
newctx MyContext as [write_props] super [defaults];
////file2.php
<?hh
function foo()[MyContext]: void {
baz(() ==> foo());
}
function bar()[MyContext]: void {
baz(()[MyContext] ==> bar());
}
function baz((function()[_]: void) $p)[ctx $p]: void {
$p();
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.