language
stringlengths 0
24
| filename
stringlengths 9
214
| code
stringlengths 99
9.93M
|
---|---|---|
PHP
|
hhvm/hphp/hack/test/typecheck/call_in_static_dict.php
|
<?hh
class C {
public static function f() {
return "lol";
}
public static $x = dict['a' => C::f()];
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/call_in_static_dict_like_array.php
|
<?hh
class C {
public static function f() {
return "lol";
}
public static $x = darray['a' => C::f()];
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/call_in_static_shape.php
|
<?hh
class C {
public static function f(): string {
return "lol";
}
public static shape('a' => string) $x = shape('a' => C::f());
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/call_in_static_varray.php
|
<?hh
class C {
public static function f(): string {
return "lol";
}
public static varray<string> $x = varray[C::f()];
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/call_in_static_vec.php
|
<?hh
class C {
public static function f() {
return "lol";
}
public static $x = vec[C::f()];
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/call_in_static_vec_like_array.php
|
<?hh
class C {
public static function f() {
return "lol";
}
public static $x = varray[C::f()];
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/call_lvalue.php
|
<?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
function foo(): int {
return 1;
}
function get_arr(): vec<int> {
return vec[];
}
function bar(): void {
$v = vec[0];
// Ban array indexing with a function receiver
// in an lvalue position.
// Good: array update in a local variable.
$v[foo()] = 1;
$v[get_arr()[0]] = 12;
// Bad: array update in a temporary value.
get_arr()[] = 1;
get_arr()[0] = 1;
list($_, get_arr()[0]) = vec[1, 2];
$vals = vec[1, 2];
foreach($vals as get_arr()[0]) {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/call_user_func_array.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 {
call_user_func(varray['my_object', 'my_method']);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/call_user_func_method.php
|
<?hh
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*
*/
class X {
public int $foo = 0;
public function foo(): void {
echo 'hello';
}
}
function test(): void {
$x = new X();
call_user_func($x->foo);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/call_vs_prop.php
|
<?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
function g():int { return 3; }
class C {
public static (function():int) $bar = g<>;
public function __construct(public (function():int) $foo) { }
public function foo():string { return "a"; }
public static function bar():string { return "b"; }
}
function expectInt(int $_):void { }
function expectString(string $_):void { }
<<__EntryPoint>>
function testit():void {
$c = new C(() ==> 1);
C::$bar = () ==> 2;
$x = $c->foo();
$y = ($c->foo)();
$f = $c->foo;
$sx = $c::bar();
$sz = ($c::$bar)();
expectString($x);
expectInt($y);
expectString($sx);
expectInt($sz);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/capitalization1.php
|
<?hh
class CamelCase {
final public function foo(int $x): void {}
}
class child extends CAMELCASE {
final public function foo(float $y): void {}
}
function ret(): camelcase {
return new cAMELcASE();
}
function foo(cAmelCase $arg): :xhp {
expect_CamelCase($arg);
$v = ret();
expect_CamelCase($v);
return new :xhp();
}
function expect_CamelCase(CamelCase $x):void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/capitalization2.php
|
//// f1.php
<?hh
class CamelCase {
final public function foo(int $x): void {}
}
//// f2.php
<?hh
function foo(cAmelCase $arg): :xhp {
expect_CamelCase($arg);
$v = ret();
expect_CamelCase($v);
return new :xhp();
}
function ret(): camelcase {
return new cAMELcASE();
}
function expect_CamelCase(CamelCase $x):void {}
class :xhp {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/capitalization3.php
|
<?hh
class CamelCase {
final public function foo(int $x): void {}
}
class CAMELCASE {
final public function bar(int $y): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/capitalization4.php
|
//// f1.php
<?hh
function CamelCase(int $x): void {}
//// f2.php
<?hh
function cAmelCase(string $y): void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/capitalization7.php
|
<?hh
class C {
public function camelCase(): void {}
}
function foo(): void {
$c = new C();
$c->camelcase();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/case_null.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum Enum: int {
A = 0;
B = 1;
C = 2;
D = 3;
}
function f(Enum $e): int {
$x = null;
switch ($e) {
case Enum::A:
$x = 1;
break;
case Enum::B:
case Enum::C:
$x = 2;
break;
case Enum::D:
return 3;
}
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/case_sensitive_inheritance1.php
|
<?hh // strict
class A {
public function foo(): void {}
}
class B extends A {
// should fail
public function FOO(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/case_sensitive_inheritance2.php
|
<?hh // strict
interface I1 {
public function foo(): void;
}
interface I2 {
public function FOO(): void;
}
// Error, foo defined twice with different casing
abstract class C implements I1, I2 {
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/case_sensitive_inheritance3.php
|
<?hh // strict
class A {
private function foo(): void {}
}
class B extends A {
// is fine, private function isn't inherited
public function FOO(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/case_sensitive_inheritance4.php
|
<?hh // strict
class A {
public static function foo(): void {}
}
class B extends A {
public static function FOO(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/case_sensitive_inheritance5.php
|
<?hh // strict
class A {
public function FOO(): void {}
}
trait T {
public function foO(): void {}
public function bar(): int {
return 0;
}
}
class B extends A {
use T;
public function FOO(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/case_sensitive_inheritance6.php
|
<?hh // strict
interface IFoo {
public function foo(): int;
}
interface IFooChild extends IFoo {
public function Foo(): float; // hh should error
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/case_sensitive_inheritance7.php
|
<?hh // strict
class A {
public function FOO(): void {}
}
class B extends A {
public static function foo(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/case_sensitive_inheritance8.php
|
<?hh
// (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the "hack" directory of this source tree.
trait MyTrait {
private function createBuildID(): string {
return "foo";
}
final public function foo(): string {
return $this->createBuildID();
}
}
final class MyA {
use MyTrait;
private static function createBuildId(): string {
return "FOO";
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/case_sensitive_inheritance9.php
|
<?hh
// (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the "hack" directory of this source tree.
class A {
public function FOO(): void {}
}
trait T {
public static function foO(): void {}
public function bar(): int {
return 0;
}
}
class B extends A {
use T;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/catch_alias.php
|
<?hh
type ExceptionAlias = Exception;
<<__EntryPoint>>
function my_main(): void {
try {
throw new Exception();
} catch (ExceptionAlias $a) {
echo "never executed";
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/catch_exception.php
|
<?hh // strict
class MyException extends Exception {
public function __construct() {
parent::__construct('dummy');
}
}
function f(): void {}
function g(): void {
try {
} catch (MyException $m) {
} catch (Exception $e) {
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/catch_newtype.php
|
<?hh
newtype ExceptionAlias = Exception;
<<__EntryPoint>>
function my_main(): void {
try {
throw new Exception();
} catch (ExceptionAlias $a) {
echo "never executed";
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/catch_non_exception.php
|
<?hh // strict
class NonException {}
function might_throw(): void {}
function f(): void {
try {
might_throw();
} catch (NonException $m) {
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/cconst.php
|
//// cconst.hhi
<?hh
class Klass {
const int X1 = 0;
const int X2;
const string Y;
const int BAD = 'hello';
}
//// cconst.php
<?hh
function test(
int $i,
string $s,
): void {}
function main(): void {
test(\ReflectionMethod::IS_PUBLIC, \DateTime::ISO8601);
test(Klass::X1, Klass::Y);
test(Klass::X1, Klass::X2);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/chained_arrows.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 foo(): this { return $this; }
public function bar(): int { return 0; }
}
function test(): bool {
return (new A())->foo()->bar();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/chained_arrows2.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 A $foo;
public int $bar;
}
function test(): bool {
return (new A())->foo->bar;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/chained_arrows3.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 int $bar;
public function __construct() {
$this->bar = 0;
}
public function foo(): this {
return $this;
}
}
function test(): int {
return (new A())->foo()->bar;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/check_override_synthesized_traits.php
|
<?hh
class A {
public function foo(int $_): void {}
}
trait T1 {
require extends A;
public function bar(int $x): void {
$this->foo($x);
}
}
trait T2 {
use T1;
public function foo(string $_): void {}
public function baz(string $x): void {
$this->foo($x);
}
}
class B extends A {
use T2;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_01.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 foo(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_02.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 {}
interface I {}
class B implements I, A {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_abstract_final_1.php
|
<?hh
abstract final class Foo {
public static function bar(): void {}
}
function takes_complex_foo(
Vector<varray<Awaitable<Foo>>> $foo
): void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_abstract_final_10.php
|
<?hh
abstract final class Foo {
public static function bar(): void {}
}
class C {
private ?Foo $member;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_abstract_final_2.php
|
<?hh
abstract final class Foo {
public static function bar(): void {}
}
class C {
public static function takes_complex_foo(
Vector<varray<Awaitable<Foo>>> $foo
): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_abstract_final_6.php
|
<?hh
abstract final class Foo {
public static function bar(): void {}
}
function takes_complex_foo<T as Vector<varray<Awaitable<Foo>>>>(
T $x
): void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_abstract_final_7.php
|
<?hh
abstract final class Foo {
public static function bar(): void {}
}
class C {
public function takes_complex_foo<T as Vector<varray<Awaitable<Foo>>>>(
T $x
): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_abstract_final_8.php
|
<?hh // strict
abstract final class Foo extends Exception {}
function f(mixed $x): void {
try {
throw new Exception('');
} catch (Foo $y) {
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_abstract_final_9.php
|
<?hh
abstract final class Foo {
public static function bar(): void {}
}
class C {
private static ?Foo $member;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_as_class_constant.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.
*
*
*/
final class DerpyClass {
const class = "derp derp";
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_as_enum_constant.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.
*
*
*/
enum DerpyEnum: string as string {
LOL = "haha";
Class = "DERP";
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_as_enum_constant2.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.
*
*
*/
enum DerpyEnum: string as string {
LOL = "haha";
class = "DERP";
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_class_bad_syntax.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 {
$i = new C();
return $i::class;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_clone_function_with_one_param.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
final class A1 {
final public function __clone(int $_): this {
return $this;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_constant_concretization.php
|
<?hh
abstract class A {
abstract const int X = 4;
}
class C extends A {}
function f(): void {
$x = C::X;
hh_show($x);
$fail = A::X;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_constant_cycle.php
|
<?hh
/* cycles without inheritance */
class C0 {
const int A = C0::B;
const int B = C0::A;
}
class D0 {
const int A = self::C;
const int B = self::A;
const int C = self::B;
}
class C {
const int A = D::X + Z::L;
const int B = self::A;
const int W = self::WW;
const int WW = Z::L + Z::Y;
const int C_SELF = self::C_SELF;
const int C_SELF2 = C::C_SELF2;
}
class Z {
const int L = 42;
const int Y = 42;
}
class D {
const int X = C::B;
}
/* cycles with inheritance */
class CE {
const int X = CF::X;
}
class CF extends CE {}
/* Same constant name but no cycle */
class C_OK { const int A = 42; }
class D_OK { const int A = C_OK::A; } // No error here
/* Indirect cycle: we report only in E_KO, not in F_OK */
class E_KO {
const int A = E_KO::B; // Error here
const int B = E_KO::A; // Error here
}
class F_OK {
const int A = E_KO::A; // No error here.
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_constant_default_resolution.php
|
<?hh
<<file:__EnableUnstableFeatures('class_const_default')>>
interface I1 {
abstract const int X = 3;
}
interface I2 {
abstract const arraykey X;
}
abstract class A {
abstract const num X;
}
class C extends A implements I1, I2 {}
function f(): void {
$x = C::X;
hh_show($x);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_const_generics.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class D<T> {
public static function m(): void {}
}
function f(): void {
D<string>::m();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_get_generics.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class D<T> {
public static int $i = 4;
}
function f(): void {
D<string>::$i;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_get_union.php
|
//// file1.php
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class A {
public static function test(bool $b, int $x): void {
$c = $b ? C1::class : C2::class;
$c::f($x);
}
}
//// file2.php
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class C1<T> {
public static function f(T $_): void {}
}
abstract class C2 extends C1<this::T> {
abstract const type T;
public static function f(this::T $_): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_level_where_clauses_disabled.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 Base <T> where T = int {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_level_where_constraint_disabled.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-level where constraints on generic T
class Base <T> where T as num {} // Class-level where clauses is not enabled
class Num_ <Tu> extends Base<Tu> where Tu = int {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth1.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 {
$p = A::f1<>;
return $p('moo');
}
class A {
public static function f1(string $s): int {
return 0;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth11.php
|
<?hh
class C {
public static function aStaticMeth(): string {
return 'C';
}
public function test(): string {
$h = static::aStaticMeth<>;
hh_show($h);
return $h() . ' ';
}
}
final class D extends C {
public function test2(): string {
$g = self::aStaticMeth<>;
hh_show($g);
return $g() . ' ';
}
public static function aStaticMeth(): string {
return 'D';
}
}
trait MyTr {
public static function aStaticMeth(): string {
return 'MyTr';
}
public function test(): string {
// static::class is the 'use'r class at runtime
$h = static::aStaticMeth<>;
hh_show($h);
return $h() . ' ';
}
}
class E {
use MyTr;
}
<<__EntryPoint>>
function main(): void {
$c = new C();
echo 'C: ', $c->test(), "\n";
$d = new D();
echo 'D: ', $d->test(), "\n";
$e = new E();
echo 'E: ', $e->test(), "\n";
}
// Expected output when executed (without hh_show's)
// C: C C C
// D: C C D
// E: MyTr MyTr MyTr
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth12.php
|
<?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
function bar(int $x, string $y):void { }
class C {
public static function foo(int $x, inout string $y):void { }
}
function testit():void {
$v = darray[
'a' => C::foo<>,
'b' => bar<>,
];
/* HHFIXME[4104] */
$v['a'](3, 'b');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth13.php
|
<?hh
// No error because class is final
final class Foo {
public static function bar(): void {
self::bar<>;
}
}
// Error because the class is not final and could be extended
class Whoops {
public static function bar(): void {
self::bar<>;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth14.php
|
<?hh
// Trait is not final
trait Whoops {
public static function bar(): void {
self::bar<>;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth2.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 {
$p = A::f1<>;
return $p('moo');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth3.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 {
use SomeTrait;
}
function foo(): int {
$p = A::f1<>;
return $p('moo');
}
function bar(): int {
$p = A::f1<>;
return $p('moo');
}
trait SomeTrait {
public static function f1(string $s): int {
return 0;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth4.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 foo(): int {
$p = A::f1<>;
return $p('moo');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth5.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 static function f1(): int {
return 1;
}
}
function foo(): int {
$p = A::f1<>;
return $p('moo');
}
function bar(): int {
$p = A::f1<>;
return $p('moo');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth6.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 static function f1(string $s): int {
return 1;
}
}
function foo(): int {
$p = A::f1<>;
hh_show($p);
return $p('moo');
}
function bar(): int {
$p = A::f1<>;
hh_show($p);
return $p('moo');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth7.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 {
private static function f1(string $s): int {
return 1;
}
}
function foo(): int {
$p = A::f1<>;
return $p('moo');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth8.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 f1(string $s): int {
return 1;
}
}
function foo(): int {
$p = A::f1<>;
return $p('moo');
}
function bar(): int {
$p = A::f1<>;
return $p('moo');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth9.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 {
protected static function f1(string $s): int {
return 1;
}
public static function f2(): (function(string): int) {
return A::f1<>;
}
public static function f3(): (function(string): int) {
return A::f1<>;
}
}
function foo(): int {
$p = A::f2();
return $p('moo');
}
function bar(): int {
$p = A::f3();
return $p('moo');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth_dollarsign.php
|
<?hh
class Foo {}
<<__EntryPoint>>
function test(): void {
$x = meth_caller('x$x', 'foo');
$y = meth_caller('Foo', 'bar$');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth_generics.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class C<T as arraykey> {
public static function nongeneric(T $x): T {
return $x;
}
public static function generic<Tu>(T $x, Tu $y): (T, Tu) {
return tuple($x, $y);
}
}
function testdirect(string $s, int $i, bool $b): (string, (int, bool)) {
return tuple(C::nongeneric($s), C::generic($i, $b));
}
function testindirect(string $s, int $i, bool $b): (string, (int, bool)) {
$f = C::nongeneric<>;
$g = C::generic<>;
return tuple($f($s), $g($i, $b));
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth_no_typedef.php
|
<?hh
class Foo {
public static function f(): void {}
}
type Bar = Foo;
function f(): (function(): void) {
return Bar::f<>;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_meth_trait.php
|
//// file1.php
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
trait MyTestTrait {
final protected static async function genTest(): Awaitable<void> {}
}
//// file2.php
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
final class MyTestClass {
use MyTestTrait;
public static function derp(): void {
self::genTest<>;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_prop_as_this.php
|
<?hh // strict
// The test proves that it is safe to allow the 'this' type as a public
// property. Attempting to assign to a property of type 'this' will fail
// if they are not the same expression dependent type.
abstract class C {
public function __construct(public this $x) {}
public function test(C $c1, C $c2, this $static): void {
// This works because both are known to be of type <static>
$static->x = $this->x;
hh_show($static->x);
hh_show($this->x);
// But since we don't know if $c1 and $c2 refer to the same type this is an
// error.
$c1->x = $c2->x;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_top_var.php
|
<?hh // strict
class BadVarExample {
public function testBadVarExample() {
$this->thisFunctionShouldExist();
}
var $foo;
public function thisFunctionShouldExist() {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_tparam_substitution_conflicts_with_method_tparam1.php
|
<?hh // strict
abstract class BaseIterable<Tv> {
public function filterInstanceOf<Tout>(
classname<Tout> $subclass,
): BaseIterable<Tout> where Tout as Tv {
throw new Exception('unimplemented');
}
}
abstract class AbstractMappedIterable<Tin, Tout>
extends BaseIterable<Tout> {}
class MappedIterable<Tv, Tnext>
extends AbstractMappedIterable<Tv, Tnext> {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/class_tparam_substitution_conflicts_with_method_tparam2.php
|
<?hh // strict
abstract class BaseIterable<Tv> {
public function filterInstanceOf<Tout>(
classname<Tout> $subclass,
): BaseIterable<Tout> where Tout as Tv {
throw new Exception('unimplemented');
}
}
abstract class AbstractMappedIterable<Tin, Tout>
extends BaseIterable<Tout> {}
class MappedIterable<Tv, Tnext>
extends AbstractMappedIterable<Tv, Tnext> {}
class A {}
class B {}
class C {}
function test(MappedIterable<A, B> $iter): BaseIterable<C> {
return $iter->filterInstanceOf(C::class);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/clone_on_nonobject.php
|
<?hh // strict
class A {
private int $foo;
private ?A $maybeObj = null;
public function __construct() {
$this->foo = 5;
}
public function cloneMe(): A {
return clone $this;
}
public function cloneMaybeObj(): A {
if ($this->maybeObj) {
return clone $this->maybeObj;
} else {
return new A();
}
}
public function cloneOther(): A {
return clone $this->foo;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/closure2.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 {
$f = function(int $x): int { return 0; };
$f('');
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/closure_nonstrict_def_typecheck.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 Foo {
public function bar(): void {
/* Should check this in nonstrict mode */
$f = function() { Foo::f1(); };
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/closure_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.
*
*
*/
class Foo {
public function thing() : void {
$x = function(?string $y = null) : void { };
$x('');
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/closure_strict_def_typecheck.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 {
/* Make sure we raise a type error for the nonexistent method access in the
* lambda below */
$f = function() { Foo::f1(); };
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/coalesce_bug.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function coalesce3<Tr, Ta as Tr, Tb as Tr, Tc as Tr>(
?Ta $a,
?Tb $b,
Tc $c,
): Tr {
return $a ?? $b ?? $c;
}
class C {}
interface I {}
function genI(): ?I {
return null;
}
function genC(bool $f, ?C $a, ?C $b, ?I $c): ?C {
$r = coalesce3($f ? $a : null, $b, genI());
return $r;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/coalesce_null_switch.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum E : string {
A = "A";
B = "B";
}
function testswitch(?E $eo):int {
$eo = $eo ?? null;
if ($eo === null)
return 0;
switch ($eo) {
case E::A : return 1;
case E::B : return 2;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/coalesce_type_hole.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function expect_int(int $_): void {}
class C {
private ?Set<string> $s = null;
private function test(): void {
$_ = $this->s ?? varray[''];
expect_int($this->s);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/collapse_equal_types.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
trait FooTrait {
public function do(): int {
return 0;
}
}
final class Foo {
use FooTrait;
}
final class Bar {
use FooTrait;
}
function sandbox(bool $b): void {
if ($b) {
$f = new Foo();
} else {
$f = new Bar();
}
$x = $f->do(); // type of $x reported as (int | int)
hh_show($x);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/collections_index_by_key_subtype.php
|
<?hh // strict
enum IntSubtype: int as int {
ZERO = 0;
}
enum StringSubtype: string as string {
FOO = 'foo';
}
interface I {}
abstract class IDerived implements I {}
function arrayTest(varray<I> $arr, IntSubtype $key): void {
$arr[$key];
}
function dictTest(darray<int, I> $dict, IntSubtype $key): void {
$dict[$key];
}
function mapTest(Map<string, I> $dict, StringSubtype $key): void {
$dict[$key];
}
function vectorTest(Vector<string> $vec, IntSubtype $idx): void {
$vec[$idx];
}
function immutableMapTest(ImmMap<string, I> $map, StringSubtype $key): void {
$map[$key];
}
function keyedContainerTest(
KeyedContainer<string, string> $container,
StringSubtype $key,
): void {
$container[$key];
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/collection_append_no_type_params.php
|
<?hh
/* HH_FIXME[4101] */
function foo1(Vector $c): void {
$c[] = 'a';
}
/* HH_FIXME[4101] */
function foo2(Map $c, Pair $p): void {
$c[] = $p;
}
/* HH_FIXME[4101] */
function foo3(Map $c, Pair<int, string> $p): void {
$c[] = $p;
}
/* HH_FIXME[4101] */
function foo4(Map $c): void {
$c[] = Pair { 42, 'b' };
}
/* HH_FIXME[4101] */
function foo5(Set $c): void {
$c[] = 73;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/collection_literals.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 f1() : Vector<int> {
return Vector {};
}
function f2() : Vector<int> {
return Vector { 1, 2 };
}
function f3() : Map<string,int> {
return Map {};
}
function f4() : Map<int,string> {
return Map { 1 => 'a' };
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/collection_mixed.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 testmap(): Map<arraykey, mixed> {
$m = Map{"s" => 1, "t" => 2};
$m[2] = 100;
return $m;
}
function testarray(): darray<mixed, int> {
$a = darray["s" => 1, "t" => 2];
$a[2] = 100;
return $a;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/collection_non_static.php
|
<?hh // strict
function get(): int {
return 1;
}
class Foo {
public Vector<int> $vec = Vector { get(), 2 };
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/collection_type_argument.php
|
<?hh
function ok_value_collection(): void {
keyset<int>[]; // OK
keyset<arraykey>[]; // OK
Set<int> {}; // OK
Vector<int> {}; // OK
}
function ok_keyed_value_collection(): void {
dict<int, int>[]; // OK
dict<arraykey, int>[]; // OK
darray<int, int>[]; // OK
darray<arraykey, int>[]; // OK
Map<arraykey, int> {}; // OK
}
function ko_value_collection(): void {
keyset<bool>[]; // KO: bool </: arraykey
}
function ko_keyed_value_collection(): void {
dict<bool, int>[]; // KO: bool </: arraykey
}
function ko_darray(): void {
darray<bool, int>[]; // KO: bool </: arraykey
}
function ko_map(): void {
Map<bool, int> {}; // KO: bool </: arraykey
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/colon_no_space.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 { return false; }
|
PHP
|
hhvm/hphp/hack/test/typecheck/colon_on_case_label.php
|
<?hh
function foo(int $x): void {
switch ($x) {
case 1;
echo "hi";
break;
default:
echo "bye";
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/compile_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.
*
*
*/
function main(): void {
echo 'OK';
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/compile_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.
*
*
*/
function main(): void {
$x = 1;
$y = 'test';
if("this$x$y" === 'this1test') {
echo 'OK';
}
else {
echo 'FAILURE: test2.1 ', "this$x$y";
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/compile_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 test_vector(): void {
$x = Vector {1, 2, 3};
$acc = 0;
foreach($x as $v) {
$acc = $acc + $v;
}
if($acc === 6) {
echo 'OK';
}
else {
echo 'FAILURE: test3.1';
}
}
function test_map(): void {
$x = Map {1 => 1, 2 => 2, 3 => 3};
$acc = 0;
foreach($x as $k => $v) {
$acc += $k + $v;
}
if($acc === 12) {
echo 'OK';
}
else {
echo 'FAILURE: test3.2';
}
}
function test_append(): void {
$x = Vector {};
$x[] = 1;
$x[] = 2;
$x[] = 3;
$acc = 0;
foreach($x as $k => $v) {
$acc += $k + $v;
}
if($acc === 9) {
echo 'OK';
}
else {
echo 'FAILURE: test3.3';
}
}
function test_tuple(): void {
$x = tuple(tuple(1, 3), 2);
list(list($y, $u), $z) = $x;
if ($y === 1 && $u === 3 && $z === 2) {
echo 'OK';
}
else {
echo 'FAILURE: test3.4';
}
}
function main(): void {
test_vector();
test_map();
test_append();
test_tuple();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/compile_test_array.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 main(): void {
$x = new Vector(null);
$z = Vector {1, 2, 3};
$t = Map {1 => 1, 2 => 2, 3 => 3};
$y = new Map(null);
$y['ff'] = 0;
$i = 0;
foreach($x as $k => $v) {
$i += $k + $v;
}
$j = 0;
foreach($x as $v) {
$j += $v;
}
$f = 0;
foreach($y as $k => $v) {
$f += $v;
if ($k === 'ff') { $f++; }
}
if ($i === 9 && $j == 6) {
echo 'OK';
}
else {
echo 'FAILURE: test4.1';
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/compile_test_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.
*
*
*/
class A {
public function __toString(): string {
return 'Afda';
}
}
class B extends A {
}
function main(): void {
$x = '11';
$y = (int)$x;
$z = new A();
$x2 = (string)$z;
$x3 = new B();
$x4 = (A)$x3;
$x5 = (false && (true)); // (true) is not a cast.
if($y === 11 && $x2 === 'Afda') {
echo 'OK';
}
else {
echo 'Failure: test_cast.1';
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/compile_test_clone.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 int $x = 0;
}
class B {
public A $y;
public int $z = 44;
public int $u = 22;
public function __construct() {
$this->y = new A();
}
public function __clone(): void {
$this->u = 51;
}
}
function main(): void {
$b = new B();
$b2 = clone $b;
$b->z = 32;
if($b2->z === 44 && $b2->u === 51 && $b2->y->x === 0) {
echo 'OK';
}
else {
echo 'Failure: test_clone.1';
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.