language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
PHP
hhvm/hphp/hack/test/typecheck/functional_transitional.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, int) $x): void { $x = tuple(1, 2); $x->f(); }
PHP
hhvm/hphp/hack/test/typecheck/functional_xhp.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:xx extends XHPTest { attribute Map<string, int> k; } class :x:xy {} class A {} function test(): void { $x = <x:xx k={Map {}}></x:xx>; }
PHP
hhvm/hphp/hack/test/typecheck/functions_without_body.php
<?hh /** * Copyright (c) 2022, 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 function_without_body(): void;
PHP
hhvm/hphp/hack/test/typecheck/function_call_incr_decr.php
<?hh function get_dict(): dict<string, int> { return dict[]; } function foobar(): void { get_dict()['lol']--; get_dict()['hah']++; }
PHP
hhvm/hphp/hack/test/typecheck/function_call_targ_illformed.php
<?hh // strict class Foo<T> {} function foo<T>(T $x) : void {} function test() : void { foo<Foo>(); // bad, missing type arg on Foo }
PHP
hhvm/hphp/hack/test/typecheck/function_hint_with_variadic_parameter.php
<?hh //strict function variadic_int(int ...$y): void {} function hint_no_args((function(): void) $f): void {} function hint_single_int((function(int): void) $f): void {} function hint_multiple_int((function(int, int, int): void) $f): void {} function hint_variadic_int((function(int...): void) $f): void {} function test(): void { hint_no_args(variadic_int<>); hint_single_int(variadic_int<>); hint_multiple_int(variadic_int<>); hint_variadic_int(variadic_int<>); $closure = function(int ...$y): void {}; hint_no_args($closure); hint_single_int($closure); hint_multiple_int($closure); hint_variadic_int($closure); $lambda = (int ...$y) ==> { }; hint_no_args($lambda); hint_single_int($lambda); hint_multiple_int($lambda); hint_variadic_int($lambda); $lambda = (...$y) ==> { }; hint_no_args($lambda); hint_single_int($lambda); hint_multiple_int($lambda); hint_variadic_int($lambda); }
PHP
hhvm/hphp/hack/test/typecheck/function_hint_with_variadic_parameter_and_arg_with_vararg.php
<?hh // This is a function of int and vararg function func_with_vararg(int $a, mixed ...$args): void {} // This is a function that takes a function of int and variadic function hint_variadic((function(int, mixed...): void) $f): void {} function test(): void { hint_variadic(func_with_vararg<>); }
PHP
hhvm/hphp/hack/test/typecheck/function_hint_with_variadic_parameter_and_non_variadic_arg.php
<?hh //strict function non_variadic(int $a, string $y): void {} function hint_variadic((function(mixed...): void) $f): void {} function test(): void { hint_variadic(non_variadic<>); }
PHP
hhvm/hphp/hack/test/typecheck/function_hint_with_variadic_parameter_contravariant.php
<?hh //strict class A {} class B extends A {} class C extends A {} class D extends C {} function variadic_A(A ...$y): void {} function hint_single_B((function(B): void) $f): void {} function hint_variadic_B((function(B...): void) $f): void {} function hint_variadic_D((function(D...): void) $f): void {} function hint_mixed_A_B_C_D((function(A, B, C, D): void) $f): void {} function hint_mixed_variadic((function(A, B, C, D...): void) $f): void {} function test(): void { hint_single_B(variadic_A<>); hint_variadic_B(variadic_A<>); hint_variadic_D(variadic_A<>); hint_mixed_A_B_C_D(variadic_A<>); hint_mixed_variadic(variadic_A<>); }
PHP
hhvm/hphp/hack/test/typecheck/function_hint_with_variadic_parameter_not_covariant_1.php
<?hh //strict class A {} class B extends A {} function variadic_B(B ...$y): void {} function hint_single_A((function(A): void) $f): void {} function test(): void { hint_single_A(variadic_B<>); }
PHP
hhvm/hphp/hack/test/typecheck/function_hint_with_variadic_parameter_not_covariant_2.php
<?hh //strict class A {} class B extends A {} function variadic_B(B ...$y): void {} function hint_variadic_A((function(A...): void) $f): void {} function test(): void { hint_variadic_A(variadic_B<>); }
PHP
hhvm/hphp/hack/test/typecheck/function_hint_with_variadic_parameter_wrong_return_type.php
<?hh //strict function variadic_int(int ...$y): void {} function hint_different_return_type((function(int): string) $f): void {} function test(): void { hint_different_return_type(variadic_int<>); }
PHP
hhvm/hphp/hack/test/typecheck/function_hint_with_variadic_parameter_wrong_type.php
<?hh //strict function variadic_int(int ...$y): void {} function hint_single_string((function(string): void) $f): void {} function test(): void { hint_single_string(variadic_int<>); }
PHP
hhvm/hphp/hack/test/typecheck/function_hint_with_variadic_parameter_wrong_types.php
<?hh //strict function variadic_int(int ...$y): void {} function hint_mixed((function(int, int, bool): void) $f): void {} function test(): void { hint_mixed(variadic_int<>); }
PHP
hhvm/hphp/hack/test/typecheck/function_hint_with_variadic_parameter_wrong_variadic_type.php
<?hh //strict function variadic_int(int ...$y): void {} function hint_variadic_string((function(string...): void) $f): void {} function test(): void { hint_variadic_string(variadic_int<>); }
PHP
hhvm/hphp/hack/test/typecheck/fun_contra.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function TakeFun((function(int): arraykey) $f): void { ($f)(3); } function Pass((function(arraykey): int) $g): void { TakeFun($g); } function DoIt(): void { Pass((arraykey $x) ==> 5); } function main(): void { DoIt(); }
PHP
hhvm/hphp/hack/test/typecheck/fun_contra_bad.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function TakeFun((function(arraykey): arraykey) $f): void { ($f)(3); } function Pass((function(int): int) $g): void { TakeFun($g); } function DoIt(): void { Pass((int $x) ==> 5); } function main(): void { DoIt(); }
PHP
hhvm/hphp/hack/test/typecheck/fun_generics_bad.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function cannot_be_nullable(int $val): int { return $val; } /* HH_FIXME[4110] */ function special_array_map<T1, T2>( (function(T1): T2) $f, darray<int, T1> $a, ): darray<int, T2> { } <<__EntryPoint>> function demo(): bool { $array = darray[]; for ($k = 0; $k < 10; $k++) { $array[$k] = null; } $fun1 = cannot_be_nullable<>; $val1 = special_array_map($fun1, $array); return (bool)$val1; }
PHP
hhvm/hphp/hack/test/typecheck/fun_no_ret.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 { $x = function() { }; return $x(); }
PHP
hhvm/hphp/hack/test/typecheck/fun_typedef.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. * * */ type X = (function(): int); function useX(X $x): int { do { return $x(); if (true) { } } while (true); return 0; }
PHP
hhvm/hphp/hack/test/typecheck/gconst.php
//// gconst.hhi <?hh const int X1 = 0; const int X2; const string Y; const FunctionCredential Z; const int BAD = 'hello'; //// gconst.php <?hh function test( int $i, string $s, FunctionCredential $fc, ): void {} function main(): void { test(__LINE__, __FUNCTION__, __FUNCTION_CREDENTIAL__); test(X1, Y, Z); test(X1, X2, Z); }
PHP
hhvm/hphp/hack/test/typecheck/gen1.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 { } function foo<T as A>(T $x): T { return $x; } function foo2<T as B>(T $x): void { foo($x); }
PHP
hhvm/hphp/hack/test/typecheck/gen2.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<T as A>(T $x): T { return $x; } } class B extends A { public function foo2<T as B>(T $x): void { } }
PHP
hhvm/hphp/hack/test/typecheck/gen3.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<T as A>(): T { return $this->foo(); } } class B extends A { public function foo<T as A>(): T { return $this->foo(); } }
PHP
hhvm/hphp/hack/test/typecheck/gen4.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<T as A>(): T { return $this->foo(); } } class B extends A { public function foo<T as B>(): T { return $this->foo(); } }
PHP
hhvm/hphp/hack/test/typecheck/gen4a.php
<?hh // strict /** * Copyright (c) 2016, 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<T as A>(T $x): T { return $this->foo($x); } } class B extends A { public function foo<T as B>(T $x): T { return $this->foo($x); } }
PHP
hhvm/hphp/hack/test/typecheck/gen6.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 as A<T>> { public function bar(T $x): T { return $x; } } class Z { public function foo(): void {} } function test(): void { $x = new A(); $x->bar(new Z())->foo(); }
PHP
hhvm/hphp/hack/test/typecheck/gen8.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 foo1<T>(T $x): T { return $x; } function foo2<T2>(T2 $x): T2 { return $x; } function foo3(int $x): int { return 0; } function test<T3>(bool $b): (function(T3): T3) { $x = $b? foo1<>: foo2<>; return $x; }
PHP
hhvm/hphp/hack/test/typecheck/gen9.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 foo1<T>(T $x): T { return $x; } function foo2<T2>(T2 $x): T2 { return $x; } function foo3(int $x): int { return 0; } function test<T3>(bool $b): (function(T3): T3) { $x = $b? foo1<>: foo3<>; return $x; }
PHP
hhvm/hphp/hack/test/typecheck/generator_ok_throw.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. * * */ async function test(?int $x): Awaitable<int> { if($x === null) { throw new Exception('Nooo'); } return $x; }
PHP
hhvm/hphp/hack/test/typecheck/generic_attr2.php
<?hh // strict class :my-xhp<T> extends XHPTest { attribute T foo @required; } function test(int $x): :my-xhp<string> { return <my-xhp foo={$x} />; }
PHP
hhvm/hphp/hack/test/typecheck/generic_capture_bad.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. abstract class Base<T> { abstract public function cast<TF>(T $x):TF; } // This is bad because we've captured TF abstract class Bad<TF> extends Base<TF> { } class Bad2 extends Bad<mixed> { public function cast<TF>(TF $x):TF { return $x; } } function breakit(Base<mixed> $x):int { return $x->cast("A"); } <<__EntryPoint>> function main():void { $b = new Bad2(); breakit($b); }
PHP
hhvm/hphp/hack/test/typecheck/generic_constructor.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class B<T> { public function __construct() {} } class C<T> { public function __construct<Tc>() {} }
PHP
hhvm/hphp/hack/test/typecheck/generic_exception.php
<?hh // strict class Foo<T> extends Exception {} function f(mixed $x): Foo<int> { try { throw new Foo(''); } catch (Foo $y) { throw $y; } }
PHP
hhvm/hphp/hack/test/typecheck/generic_fst_bad.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. function fst<T1,T2>(T1 $x, T2 $y):T2 { return $x; }
PHP
hhvm/hphp/hack/test/typecheck/generic_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. * * */ function id<T>(T $x): T { return $x; } function test(): (function(int): int) { return id<>; }
PHP
hhvm/hphp/hack/test/typecheck/generic_fun_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. * * */ function id<T>(T $x): T { return $x; } function test(): ((function(int): int), (function(string): string)) { $f = id<>; return tuple($f, $f); }
PHP
hhvm/hphp/hack/test/typecheck/generic_fun_3.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function darray_filter<Tk as arraykey, Tv>( KeyedTraversable<Tk, Tv> $traversable, ?(function(Tv): bool) $f, ): darray<Tk, Tv> { return darray[]; } function is_not_null<T>(T $x): bool { return false; } class C {} class D {} function testit(varray<?C> $vc, varray<?D> $vd): void { $func = is_not_null<>; $a = darray_filter($vd, $func); $b = darray_filter($vc, $func); }
PHP
hhvm/hphp/hack/test/typecheck/generic_incompatible_implementation.php
<?hh class C<T> {} class D {} class Foo implements Bar { public function f<T>(C<T> $x): void {} } interface Bar { public function f<T>(C<D> $x): void; }
PHP
hhvm/hphp/hack/test/typecheck/generic_incompatible_implementation2.php
<?hh class C<T> {} class Foo implements Bar { public function f<T as num>(C<T> $x): void {} } interface Bar { public function f<T>(C<T> $x): void; }
PHP
hhvm/hphp/hack/test/typecheck/generic_method_rename_override.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. trait TR { protected abstract function foo<Tv as nonnull>(C<Tv> $step): Tv; } final class FC extends AC<void> { use TR; } abstract class AC<Tv> extends C<Tv> { // Hack will rename foo's method type parameters away from Tv } abstract class C<+Tstep> { public function foo<Tv as nonnull>(C<Tv> $step): Tv { throw new Exception("A"); } }
PHP
hhvm/hphp/hack/test/typecheck/generic_optional_type.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<T> { public function f1(T $x): void { } } function f2(): Foo<?int> { $f = new Foo(); $f->f1(null); return $f; }
PHP
hhvm/hphp/hack/test/typecheck/generic_primitive_invariant.php
<?hh /* * We should be able to inline addone and get the same error; * however, due to a TODO for arithmetic operators in Typing, this does not work * * See the TODO in Ast.Minus | Ast.Star in typing.ml for more details */ function addone(int $x): int { return $x + 1; } function no<T as int>(T $i): T { return addone($i); }
PHP
hhvm/hphp/hack/test/typecheck/generic_subtype_mixed_bad.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test<T1, T2 super int>(T1 $x): ?T2 { return $x; }
PHP
hhvm/hphp/hack/test/typecheck/generic_subtype_mixed_good.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. function test<T1, T2 super nonnull>(T1 $x): ?T2 { return $x; }
PHP
hhvm/hphp/hack/test/typecheck/generic_subtyping.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 I {} class A extends I {} class B extends I {} function foo<T as I>(T $x): void {} function test(): void { if(true) { $y = new B(); } else { $y = new A(); } foo($y); }
PHP
hhvm/hphp/hack/test/typecheck/generic_subtyping2.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 I {} class A extends I {} class B extends I {} class UnrelatedClass {} function foo<T as I>(T $x): void {} function test(bool $b): void { if ($b) { $y = new B(); } else { $y = new UnrelatedClass(); } foo($y); }
PHP
hhvm/hphp/hack/test/typecheck/generic_subtyping3.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 TestGeneric<T> { private T $obj; public function __construct(T $obj) { $this->obj = $obj; } public function get(): T { return $this->obj; } } function testGeneric<T, Tc as TestGeneric<T> >(Vector<Tc> $tests): Vector<T> { $results = Vector {}; foreach ($tests as $test) { $results[] = $test->get(); } return $results; } function testBool(bool $arg): void {} function test(): void { $objs = Vector { new TestGeneric(1), new TestGeneric(2), }; $results = testGeneric($objs); foreach ($results as $result) { // Hack should complain it's an int ! testBool($result); } }
PHP
hhvm/hphp/hack/test/typecheck/generic_subtyping4.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 TestGeneric<T> { private T $obj; public function __construct(T $obj) { $this->obj = $obj; } public function get(): T { return $this->obj; } } class X<T, Tc as TestGeneric<T> > { public Vector<T> $vec; public function __construct(Vector<Tc> $tests) { $results = Vector {}; foreach ($tests as $test) { $results[] = $test->get(); } $this->vec = $results; } public function getVector(): Vector<T> { return $this->vec; } } function testBool(bool $arg): void {} function test(): void { $objs = Vector { new TestGeneric(1), new TestGeneric(2), }; $results = (new X($objs))->getVector(); foreach ($results as $result) { // Hack should complain it's an int ! testBool($result); } }
PHP
hhvm/hphp/hack/test/typecheck/generic_subtyping5.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 TestGeneric<T> { private T $obj; public function __construct(T $obj) { $this->obj = $obj; } public function get(): T { return $this->obj; } } class X<T, Tc as TestGeneric<T> > { public Vector<T> $vec; public function __construct(Vector<Tc> $tests) { $results = Vector {}; foreach ($tests as $test) { $results[] = $test->get(); } $this->vec = $results; } } function testBool(bool $arg): void {} function test(): void { $objs = Vector { new TestGeneric(1), new TestGeneric(2), }; $results = (new X($objs))->vec; foreach ($results as $result) { // Hack should complain it's an int ! testBool($result); } }
PHP
hhvm/hphp/hack/test/typecheck/generic_this.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ interface IFoo<T> {} class Bar {} final class Foo<T as Bar> implements IFoo<T> { public function me(): this { return $this; } }
PHP
hhvm/hphp/hack/test/typecheck/generic_this_chain.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 Gen<T> { public function __construct(public T $data) {} } <<__ConsistentConstruct>> class Base<T> { public function __construct(private Gen<T> $data) {} public function get(): T { return $this->data->data; } public function set(mixed $val): this { return $this; } public function magic(mixed ...$args): this { return $this; } public static function make(Gen<T> $data): this { return new static($data); } } class X {} class Child extends Base<X> {} final class Another<T> { private ?Gen<T> $data; public function set(Gen<T> $data): this { $this->data = $data; return $this; } public function magicGetter(mixed ...$args): ?T { return $this->data ? $this->data->data : null; } public static function make(Gen<T> $data): this { $i = new static(); $i->set($data); return $i; } } function takesX(X $arg): void {} function test(int $i): Base<X> { $x = new X(); switch ($i) { case 0: $thing = new Base(new Gen($x)); break; case 1: $thing = Base::make(new Gen($x)); break; case 2: $thing = new Child(new Gen($x)); break; default: $thing = Child::make(new Gen($x)); break; } $chain = $thing->set(1)->set('foo')->set(new stdClass()); $after_chain = $chain->get(); // hh_show($after_chain); takesX($after_chain); $ret = $chain->magic()->magic(1, 2)->magic(1,2,'foo',4,new stdClass()); $dt = $ret->get(); // hh_show($dt); takesX($dt); return $ret; } function test_generic_non_this(): void { $thing = new Another(); // hh_show($thing); $s = $thing->set(new Gen(new X())); // hh_show($s); $x = $s->magicGetter(); // hh_show($x); if (null !== $x) { takesX($x); } }
PHP
hhvm/hphp/hack/test/typecheck/gen_constraint_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. * * */ function lol_wat<T1, T2 as T1>(T1 $arg1, T2 $arg2): mixed { return lol_wat($arg1, $arg2); }
PHP
hhvm/hphp/hack/test/typecheck/gen_trait1.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. * * */ trait MyTrait<T> { protected Vector<T> $a; public function test(): T { return $this->a[0]; } } class A { use MyTrait<int>; public function __construct(int $x) { $this->a = Vector { $x }; } }
PHP
hhvm/hphp/hack/test/typecheck/gen_trait2.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. * * */ trait MyTrait<T> { protected Vector<T> $a; public function test(): T { return $this->a[0]; } } class A { use MyTrait<A>; public function __construct(A $x) { $this->a = Vector { $x }; } }
PHP
hhvm/hphp/hack/test/typecheck/gen_trait3.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. * * */ trait MyTrait<T as A> { protected Vector<T> $a; public function test(): T { $this->a[0]->test(); return $this->a[0]; } } class A { use MyTrait<A>; public function __construct(A $x) { $this->a = Vector { $x }; } }
PHP
hhvm/hphp/hack/test/typecheck/gen_trait4.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. * * */ trait MyTrait<T> { protected Vector<T> $a; } class B { } function takesVectorA(Vector<A> $x): void {} class A extends B { use MyTrait<B>; public function __construct() { $a = Vector {new A()}; $this->a = $a; takesVectorA($a); } }
PHP
hhvm/hphp/hack/test/typecheck/global_const25.php
<?hh // strict namespace NS1\NS2 { const int X = 0; } function test(): int { return \NS1\NS2\X; }
PHP
hhvm/hphp/hack/test/typecheck/global_const26.php
<?hh // strict namespace NS1\NS2 { const int X = 0; } function test(): int { return \NS1\NS2\Y; }
PHP
hhvm/hphp/hack/test/typecheck/global_require_once_parse.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. * * */ require_once "help/me/rhonda"; function blah(): void { return; }
PHP
hhvm/hphp/hack/test/typecheck/global_require_once_parse2.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. * * */ require_once("help/me/rhonda"); function blah(): void { return; }
PHP
hhvm/hphp/hack/test/typecheck/group_use_needs_semicolon.php
<?hh // strict namespace Foo\Bar\Baz { function f1(): void {} function f2(): void {} const int CN = 1; class CL {} class CL2 {} } namespace Y { use Foo\Bar\Baz\{CL, function f1, const CN, CL2}; function foo(): void {} } namespace X { use Foo\Bar\Baz\{CL, function f1, const CN, CL2} function foo(): void {} }
PHP
hhvm/hphp/hack/test/typecheck/heredoc.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 { $a = <<<END This is a heredoc. END; print $a; $interpolation = "an interpolated value"; $b = <<< END This is a heredoc with $interpolation. END; $c = <<<END This one has whitespace and a misleading "end". END END; $d = <<<END Words Words Words Words END; } class Test { public string $a; public function __construct() { $this->a = 'A'; } public function __toString(): string { return '<Test>'; } } function test2(): void { $test = new Test(); print <<<identifier_with_underscores_and_like_50_characters $test = <Test> $test->a = a \x41 = A identifier_with_underscores_and_like_50_characters; }
PHP
hhvm/hphp/hack/test/typecheck/heredoc_bad_identifier.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 main(): void { $a = <<<9 Should not work. 9; }
PHP
hhvm/hphp/hack/test/typecheck/heredoc_ignored_in_decl.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 Test { public function f(): string { return <<<END public function testFunctionWithReturnTypeHavingAngleBrackets(): array<int> { return varray[]; } END; } }
PHP
hhvm/hphp/hack/test/typecheck/heredoc_missing_end.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 main(): void { $x = <<<END Here is some heredoc content. }
PHP
hhvm/hphp/hack/test/typecheck/heredoc_missing_identifier.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 main(): void { $x = <<< }
PHP
hhvm/hphp/hack/test/typecheck/hhfixme_bug.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. function testit( KeyedTraversable<arraykey, mixed> $kt ): void { $m = new Map($kt); }
PHP
hhvm/hphp/hack/test/typecheck/hhfixme_bug2.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. function setTimeStart(arraykey $ak):void { } function maxva<T as num>(T $x, T $y): T { return $x; } function testit(int $cutoff_time, ?int $start):void { /* HH_FIXME[4323] Exposed by adding return types to partial mode files */ setTimeStart(maxva<_>($cutoff_time, $start)); }
PHP
hhvm/hphp/hack/test/typecheck/hhfixme_bug4.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. function expectFun((function():void) $f):void { } function badreturn(bool $b):void { expectFun(() ==> { if ($b) { // We don't expect this FIXME to silence the second return statement! /* HH_FIXME[4110] */ return; } else { return 3; } }); }
PHP
hhvm/hphp/hack/test/typecheck/hh_expect.php
<?hh function f(int $i) : void { hh_expect<int>($i); hh_expect<mixed>($i); hh_expect<nothing>($i); hh_expect<string>($i); hh_expect_equivalent<int>($i); hh_expect_equivalent<mixed>($i); hh_expect_equivalent<nothing>($i); hh_expect_equivalent<string>($i); }
PHP
hhvm/hphp/hack/test/typecheck/hh_expect_tyvar.php
<?hh function f() : void { $v = Vector {}; hh_expect<Vector<int>>($v); $v = Vector {}; hh_expect_equivalent<Vector<int>>($v); }
PHP
hhvm/hphp/hack/test/typecheck/hh_fixme10.php
<?hh function test(): int { /* HH_FIXME[4110]: Applied to the line of the next token, even if there is * a blank line inbetween. */ return ''; }
PHP
hhvm/hphp/hack/test/typecheck/hh_fixme12.php
<?hh function f(string $s): string { return $s; } function g(): void { $xhp = <p /* HH_FIXME[4110] in XHP attrs */ class={f(1)}> para </p>; } class :p extends XHPTest { attribute string class; }
PHP
hhvm/hphp/hack/test/typecheck/hh_fixme13.php
<?hh function f(string $s): void {} function g(): void { $xhp = <p> /* HH_FIXME[4110] This is actually part of the XHP and will be rendered to the page, and so is not safe and shouldn't be accepted as a FIXME! */ {f(1)} </p>; } class :p extends XHPTest {}
PHP
hhvm/hphp/hack/test/typecheck/hh_fixme14.php
<?hh function lol(mixed $x): string { return 'lol'; } function f(): int { $n = null; /* HH_FIXME[4110] Allow two FIXMEs one after another */ /* HH_FIXME[4064] Allow two FIXMEs one after another */ return lol($n->a); }
PHP
hhvm/hphp/hack/test/typecheck/hh_fixme5.php
<?hh // strict class Bar {} class Foo {} abstract class C { abstract public function f(): Bar; } abstract class D extends C { /* HH_FIXME[4341] */ abstract public function f(): Foo; }
PHP
hhvm/hphp/hack/test/typecheck/hh_fixme7.php
//// newtype.php <?hh // strict newtype FBID = int; //// usage.php <?hh // strict class C { /* HH_FIXME[4338] */ const FBID mark = 4; }
PHP
hhvm/hphp/hack/test/typecheck/hh_fixme8.php
<?hh function test(): int { /* HH_FIXME[4110]: when there is nothing after the comment other than * white spaces and newline (like in this case), the HH_FIXME is applied * to the next line. */ return ''; }
PHP
hhvm/hphp/hack/test/typecheck/hh_fixme9.php
<?hh function test(): int { /* HH_FIXME[4110]: Applied to the line of the next token. */ /* Even if there is another comment inbetween. */ return ''; }
PHP
hhvm/hphp/hack/test/typecheck/hh_fixme_disjunction.php
<?hh // strict // Copyright 2004-present Facebook. All Rights Reserved. class Ref<T> { public function __construct(public T $value) {} public function get(): T { return $this->value; } public function set(T $value): void { $this->value = $value; } } class C {} function test2(bool $b1, bool $b2, C $c1, C $c2, C $c3): void { $r = new Ref(null); if ($b1) { $r->set($c1); } if ($b2) { $r->set($c2); } if ($r->get() !== null) { $r->set($c3); } }
hhvm/hphp/hack/test/typecheck/HH_FLAGS
--disallow-discarded-nullable-awaitables --allowed-fixme-codes-strict 1002,2049,2053,2063,4009,4029,4030,4051,4054,4055,4064,4090,4101,4102,4110,4123,4323,4338,4341,9999 --allowed-decl-fixme-codes 1002,2049,2053,4030,4054,4101,4338,4341 --extra-builtin ../hhi/XHPTest.hhi
PHP
hhvm/hphp/hack/test/typecheck/hh_show.php
<?hh // strict /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function foo(int $x): void { hh_show($x); }
PHP
hhvm/hphp/hack/test/typecheck/hh_show_typevar.php
<?hh // strict class Foo {} function test1<Ta super Tb, Tb as Foo>(Ta $x, Tb $y): void { hh_show($x); hh_show($y); return; } function test2<Ta as Tb, Tb super Foo>(Ta $x, Tb $y): void { hh_show($x); hh_show($y); return; }
PHP
hhvm/hphp/hack/test/typecheck/higher_kinded_type_constraints1.php
<?hh // This is the first file out of two to codify the exact scoping behavior of // (nested) type parameters, including all corner cases. // You should maintain the property that there is only a single Habstr in the // resulting NAST file, which means you can just search for "Habstr" in the // result file to check that it is correct // This is just to make this a self-contained file without type errors type T2 = mixed; type T4 = mixed; type T6 = mixed; type T7 = mixed; class Test< Tx as T1, // T1 is in scope: must yield only Habstr in NAST file T1<T2 as T7>, // T7 not in scope, must yield Happly referring to alias above T3<T4 as T2, // T2 not in scope, must yield Happly referring to alias above T5<T6>, T7 as T6>, // T6 not in scope, must yield Happly referring to alias above T8 as T4, // T4 not in scope, must yield Happly referring to alias above > {}
PHP
hhvm/hphp/hack/test/typecheck/higher_kinded_type_constraints2.php
<?hh // This is the second file out of two to codify the exact scoping behavior of // (nested) type parameters, including all corner cases. // You should maintain the property that there is only a single Happly in the // resulting NAST file, which means you can just search for "Happly" in the // result file to check that it is correct // This is just to make this a self-contained file without type errors type T7 = mixed; class Test< T1 as T8, // T8 in scope, must yield Habstr T2< T3 as T1, // T1 in scope, must yield Habstr T4 as T2, // T2 in scope, must yield Habstr T5 as T4, // T4 in scope, must yield Habstr T6 as T7, // T7 in scope, must yield Habstr T7<T8 as T9>, // T9 in scope, must yield Habstr T9> as (T3, T9), // T3, T9 in scope, must yield Habstr T8 as T2, // T2 in scope, must yield Habstr Tx as T3 // T3 refers to typedef above, not the tparam T3, // must yield only Happly in the restult NAST file > {}
PHP
hhvm/hphp/hack/test/typecheck/idx2_1.php
<?hh // strict function m(): Map<string, int> { return Map {}; } function f(): ?int { $m = m(); $x = idx($m, 'a'); return $x; }
PHP
hhvm/hphp/hack/test/typecheck/idx2_2.php
<?hh // strict function m(): Map<string, int> { return Map {}; } function f(): int { $m = m(); $x = idx($m, 'a'); return $x; }
PHP
hhvm/hphp/hack/test/typecheck/idx2_3.php
<?hh // strict function m(): Map<string, int> { return Map {}; } function f(): ?int { $m = m(); // XXX this ideally would fail, should KeyedContainer be covariant? Task #5343698 $x = idx($m, 0); return $x; }
PHP
hhvm/hphp/hack/test/typecheck/idx2_4.php
<?hh // strict function m(): Map<string, int> { return Map {}; } function f(): ?int { $m = m(); $x = idx(0, 'a'); return $x; }
PHP
hhvm/hphp/hack/test/typecheck/idx2_5.php
<?hh // strict function f(?int $x, Map<string, ?int> $y): void { g($x, idx($y, 'foo')); } function g<T>(T $_, T $_): void {}
PHP
hhvm/hphp/hack/test/typecheck/idx3_1.php
<?hh // strict function m(): Map<string, int> { return Map {}; } function f(): int { $m = m(); $x = idx($m, 'a', 0); return $x; }
PHP
hhvm/hphp/hack/test/typecheck/idx3_2.php
<?hh // strict function m(): Map<string, int> { return Map {}; } function f(): string { $m = m(); $x = idx($m, 'a', 0); return $x; }
PHP
hhvm/hphp/hack/test/typecheck/idx3_3.php
<?hh // strict function m(): Map<string, int> { return Map {}; } function f(): int { $m = m(); $x = idx($m, 'a', 'blah'); return $x; }
PHP
hhvm/hphp/hack/test/typecheck/idx3_4.php
<?hh // strict function m(): Map<string, int> { return Map {}; } function f(): int { $m = m(); // XXX this ideally would fail, should KeyedContainer be covariant? Task #5343698 $x = idx($m, 0, 0); return $x; }
PHP
hhvm/hphp/hack/test/typecheck/idx3_5.php
<?hh // strict function m(): Map<string, int> { return Map {}; } function f(): int { $m = m(); $x = idx(0, 'a', 0); return $x; }
PHP
hhvm/hphp/hack/test/typecheck/idx_bug.php
<?hh // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. function test(mixed $c, string $id):int { if (!($c is KeyedContainer<_, _>)) { return 1; } if (idx($c, $id) === null) { return 2; } return 3; }
PHP
hhvm/hphp/hack/test/typecheck/idx_too_few_args.php
<?hh // strict function m(): Map<string, int> { return Map {}; } function f(): ?int { $m = m(); $x = idx($m); return $x; }
PHP
hhvm/hphp/hack/test/typecheck/idx_too_many_args.php
<?hh // strict function m(): Map<string, int> { return Map {}; } function f(): ?int { $m = m(); $x = idx($m, 'a', null, null); return $x; }
PHP
hhvm/hphp/hack/test/typecheck/if1.php
<?hh /** * Copyright (c) 2014, Facebook, Inc. * All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the "hack" directory of this source tree. * * */ function test(): int { $x = 0; if(true) { throw new Exception(''); } else { throw new Exception(''); } return $x; }