language
stringlengths 0
24
| filename
stringlengths 9
214
| code
stringlengths 99
9.93M
|
---|---|---|
PHP
|
hhvm/hphp/hack/test/typecheck/invariant_return.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 invariant(1, ""); }
function foo2(): bool { return invariant(true, ""); }
|
PHP
|
hhvm/hphp/hack/test/typecheck/isset3.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 {
$x = 0;
isset($x[1]);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/is_as_no_check_unbound_name.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
class A<T> {}
function f(): void {
// This will not produce a 4195 error now
3 as B<int>;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/iterator.php
|
<?hh
final class ConstantIterator<T> implements Iterator<T> {
public function __construct(private T $value) {}
public function current(): T { return $this->value; }
public function next(): void {}
public function rewind(): void {}
public function valid(): bool { return true; }
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/keys.php
|
<?hh
/**
* Tuple-like arrays have integer keys
*/
function test(): void {
$a = varray[true];
take_int_indexed_array($a);
}
function take_int_indexed_array<Tv>(darray<string, Tv> $a): void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/key_exists_optional_nothing.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function test(shape(?'a' => nothing) $s): void {
if (Shapes::keyExists($s, 'a')) {
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/key_exists_refines_bad2.php
|
<?hh // strict
function expect_string(string $_): void {}
function test(shape(...) $s): void {
if (Shapes::keyExists($s, 'x') && $s['x'] !== null) {
expect_string($s['x']);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/key_exists_refines_union_bad.php
|
<?hh // strict
function expect_int(int $_): void {}
function test(bool $b, shape(?'x' => int) $s1, shape(...) $s2): void {
if ($b) {
$s = $s1;
} else {
$s = $s2;
}
if (Shapes::keyExists($s, 'x')) {
expect_int($s['x']);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lambda_extractor.php
|
<?hh // strict
final class LamdbaExtractor {
private static function run(string $program, int $line): void {
$json = HH\ffp_parse_string($program);
$funs = HH\ExperimentalParserUtils\find_all_functions($json);
$function = $funs[$line];
$bounds = HH\ExperimentalParserUtils\body_bounds($function);
list($begin, $end) = $bounds;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lambda_in_pipe.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function vec_filter(vec<int> $v, (function (int): bool) $_f): vec<int> {
return $v;
}
function test(vec<int> $v): vec<int> {
return $v |> vec_filter($$, function ($x) { return true; });
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/legacy_initializer.php
|
<?hh
class Foo {
const vec<vec<int>> constNested = vec[
HH\array_mark_legacy(vec[]),
];
public static vec<vec<int>> $spropNested = vec[
HH\array_mark_legacy(vec[]),
];
public vec<vec<int>> $propNested = vec[
HH\array_mark_legacy(vec[]),
];
}
const vec<vec<int>> gconstNested = vec[
HH\array_mark_legacy(vec[]),
];
const gconstWithoutHintNested = vec[
HH\array_mark_legacy(vec[]),
];
|
PHP
|
hhvm/hphp/hack/test/typecheck/lexing_stack_fail.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 {
attribute
enum { "left", "right", "center", "justify", "char" } align,
enum { "top", "middle", "bottom", "baseline" } valign;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/line_file_directives.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_LINE(): int {
return __LINE__;
}
function test_FILE(): string {
return __FILE__;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list.php
|
<?hh
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*
*/
class A {
public function foo(): void {
$x = 1;
$y = 2;
$this->list($x, $y) = 10;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_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(): int {
list($x, $y) = varray[1, 2];
return $x;
}
function test3(varray<int> $x): int {
list($x, $y) = $x;
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_array2.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 test3(varray<float> $x): int {
list($x, $y) = $x;
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_array3.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 test3(darray<int, int> $x): int {
list($x, $y) = $x;
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_array_assign.php
|
<?hh // strict
function test(varray<int> $v): (varray<int>, int, int) {
$a = list($x, $y) = $v; // list returns an array, so the $a = list() is ok.
return tuple($a, $x, $y);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_assign.php
|
<?hh // strict
function test<T as Vector<int>>(Vector<int> $vec, T $list): (int, int) {
list($x, $y) = $vec;
hh_show($x);
hh_show($y);
list($i1, $i2) = $list;
hh_show($i1);
hh_show($i2);
return tuple($i1, $i2);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_assign_union.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function f(vec<int> $a, (string, bool) $b, bool $x): void {
$z = $x ? $a : $b;
list($a, $b) = $z;
hh_show($a);
hh_show($b);
}
function g((int, string) $a, Pair<bool, float> $b, bool $x): void {
$z = $x ? $a : $b;
list($a, $b) = $z;
hh_show($a);
hh_show($b);
}
function h((float, bool) $a, dynamic $b, bool $x): void {
$z = $x ? $a : $b;
list($a, $b) = $z;
hh_show($a);
hh_show($b);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_assign_unresolved_pair.php
|
<?hh // strict
interface I {}
class A implements I {}
class B implements I {}
function test(bool $b): I {
list($x1, $x2) = $b ? Pair { 1, new A() } : Pair { 2, new B() };
return $x2;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_assign_vec.php
|
<?hh // strict
function test<T as vec<int>>(vec<int> $vec, T $list): (int, int) {
list($x, $y) = $vec;
hh_show($x);
hh_show($y);
list($a, $b) = vec['asterix', 'obelix'];
hh_show($a);
hh_show($b);
list($i1, $i2) = $list;
hh_show($i1);
hh_show($i2);
return tuple($i1, $i2);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_destructuring_cross_file.php
|
//// file1.php
<?hh
function f1(): (int, string, bool) {
throw new Exception();
}
//// file2.php
<?hh
function f2(): void {
$c = f1();
list($a, $b) = $c;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_destructuring_dynamic.php
|
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.
function dynamic(dynamic $d): void {
list($a, $b) = $d;
hh_show($a);
hh_show($b);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_destructuring_intersection.php
|
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.
interface I1 {}
interface I2 {}
interface I3 {}
interface I4 {}
function intersect(mixed $m): void {
if ($m is (I1, I2) && $m is (I3, I4)) {
list($a, $b) = $m;
hh_show($a);
hh_show($b);
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_destructuring_pair.php
|
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.
function pair(Pair<int, string> $p): void {
list($a, $b) = $p;
hh_show($a);
hh_show($b);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_destructuring_tvar.php
|
<?hh
class Box<T> {
public function put(T $x): void {}
public function get(): T { throw new Exception(); }
}
function pull<Tk, Tv1, Tv2>(
Tv1 $input,
(function(Tv1): Tv2) $value_func,
(function(Tv1): Tk) $key_func,
): void {
throw new Exception();
}
interface A1 {}
interface A2 {}
interface B1 {}
interface B2 {}
function test((A1, A2) $t1, (B1, B2) $t2): void {
$x = new Box(); // Box<#1>
$x->put($t1);
$x->put($t2);
$input = $x->get(); // {(A1, A2), (B1, B2)} <: #1
pull(
$input,
$in ==> {
list(
$v1, // A1 <: #3 /\ B1 <: #3
$v2 // A2 <: #4 /\ B2 <: #4
) = $in; // (A1, A2) <: list(#3, #4) /\ (B1, B2) <: list(#3, #4);
},
$in ==> {
list($v1, $v2) = $in; // same as above
hh_force_solve();
hh_show($v1);
hh_show($v2);
},
);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_destructuring_union.php
|
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.
function union(bool $x, dynamic $d, (int, string) $tup): void {
$like = $x ? $d : $tup;
list($a, $b) = $like;
hh_show($a);
hh_show($b);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_destructuring_varray.php
|
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.
function varrays(varray<int> $a1, varray<string> $a2): void {
list($a, $b) = $a1;
hh_show($a);
hh_show($b);
list($c, $d) = $a2;
hh_show($c);
hh_show($d);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_destructuring_vec.php
|
<?hh
// Copyright 2004-present Facebook. All Rights Reserved.
function vecs(Vector<int> $v1, ImmVector<float> $v2, ConstVector<string> $v3, vec<bool> $v4): void {
list($a, $b) = $v1;
hh_show($a);
hh_show($b);
list($c, $d) = $v2;
hh_show($c);
hh_show($d);
list($e, $f) = $v3;
hh_show($e);
hh_show($f);
list($g, $h) = $v4;
hh_show($g);
hh_show($h);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_generic_assign.php
|
<?hh // strict
// It's illegal to assign a generic to a tuple
function test<T>(T $v): void {
list($x, $y) = $v;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_non_static.php
|
<?hh // strict
function get(): int {
return 1;
}
class Foo {
public (int, int, int) $list_tuple = list(get(), 3, 4);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_pair.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(Pair<string, string> $v): string {
list($x, $y) = $v;
return $y;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_pair2.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(Pair<string, string> $v): string {
list($x) = $v;
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_pair_assign.php
|
<?hh // strict
function test(Pair<int, string> $v): (Pair<int, string>, int, string) {
$a = list($x, $y) = $v; // list returns an array, so the $a = list() is ok.
return tuple($a, $x, $y);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_read.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 static Map<int, (int, int)> $data = Map {};
private int $a, $b;
public function __construct(int $idx) {
list($this->a, $this->b) = self::$data[$idx];
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_union_tuple_assign.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function foo(bool $b): arraykey {
if ($b) {
$a = tuple(42, 1);
} else {
$a = tuple('bar', 2);
}
list($x, $y) = $a;
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_union_tuple_assign_bad.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function foo(bool $b): int {
if ($b) {
$a = tuple(42, 1);
} else {
$a = tuple('bar', 2);
}
list($x, $y) = $a;
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_varray.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 {
list($x, $y) = varray[1, 2];
return $x;
}
function test2(varray<int> $x): int {
list($x, $y) = $x;
return $x;
}
function test3(varray<int> $x): bool {
list($x, $y) = $x;
return $x;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/list_vector.php
|
<?hh // strict
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*
*/
function foo(Vector<int> $vector): void {
list($x, $y) = $vector;
}
function bar(ConstVector<int> $vector): void {
list($x, $y) = $vector;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/loader_example.php
|
<?hh // strict
interface ILoader<T> {
public static function gen(): Awaitable<T>;
public function set(T $x);
}
abstract class Loader implements ILoader<this::TLoadsType> {
abstract const type TLoadsType;
public function set(this::TLoadsType $x): void {}
}
<<__ConsistentConstruct>>
abstract class SelfLoader extends Loader {
const type TLoadsType = this;
public static async function gen(): Awaitable<this::TLoadsType> {
return new static();
}
}
class ALoader extends SelfLoader {}
class BLoader extends ALoader {}
class OtherALoader extends Loader {
const type TLoadsType = ALoader;
public static async function gen(): Awaitable<ALoader> {
return new BLoader();
}
}
async function test(): Awaitable<void> {
concurrent {
$a = await ALoader::gen();
$b = await BLoader::gen();
$o = await OtherALoader::gen();
}
$a->set($o);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/logical_binop2.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 int $and = 0;
}
function f(): void {
$c = new C();
$c->and = 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/loop_switch_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(int $a): void {
do {
switch ($a) {
default:
break;
}
} while (false);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/loop_switch_continue.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 $a): void {
do {
switch ($a) {
default:
continue;
}
} while (false);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_disallow_override_private.php
|
<?hh // strict
class A {
<<__LSB>> private static int $x = 0;
}
class B extends A {
private static int $x = 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_disallow_override_protected.php
|
<?hh // strict
class A {
<<__LSB>> protected static int $x = 0;
}
class B extends A {
protected static int $x = 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_disallow_override_public.php
|
<?hh // strict
class A {
<<__LSB>> public static int $x = 0;
}
class B extends A {
public static int $x = 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_disallow_override_subclass.php
|
<?hh // strict
class A {
<<__LSB>> private static int $x = 0;
}
class B extends A {
}
class C extends B {
private static int $x = 1;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_dynamic_access.php
|
<?hh // strict
class A {
<<__LSB>> public static int $x = 1;
<<__LSB>> public static ?this $y = null;
}
class B {
public static function foo(classname<A> $cls): int {
return $cls::$x;
}
public static function bar<T as A>(classname<T> $cls): ?T {
return $cls::$y;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_nonstatic_disallowed.php
|
<?hh // strict
class C {
<<__LSB>> public int $id;
public function __construct() {
$this->id = 0;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_parent_disallowed.php
|
<?hh // strict
class A {
<<__LSB>> public static int $x = 0;
}
class B extends A {
public static function foo(): int {
return parent::$x;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_private_disallow.php
|
<?hh // strict
class A {
<<__LSB>> private static int $x = 0;
}
class B extends A {
public static function foo(): int {
return static::$x;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_property_visibility.php
|
<?hh
class Foo {
<<__LSB>>
private static int $bar = 1;
}
class Qux extends Foo {}
function baz(): void {
Foo::$bar;
Qux::$bar;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_protected_disallow_direct.php
|
<?hh // strict
class A {
<<__LSB>> protected static string $y = "!";
}
class B {
public static function foo(): string {
return A::$y;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_protected_disallow_subclass.php
|
<?hh // strict
class A {
<<__LSB>> protected static string $y = "!";
}
class B extends A {
}
class C {
public static function foo(): string {
return B::$y;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_protected_visibility.php
|
<?hh // strict
class A {
<<__LSB>> protected static string $y = "!";
public static function foo(): string {
return static::$y; // ok
}
}
class B extends A {
public static function foo(): string {
return static::$y; // ok
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_public_visibility.php
|
<?hh // strict
class A {
<<__LSB>> public static int $x = 0;
public static function foo(): int {
return static::$x; // ok
}
}
class B extends A {
public static function bar(): int {
return static::$x; // ok
}
}
class C {
public static function baz(): int {
return A::$x; // ok
}
public static function qux(): int {
return B::$x; // ok
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_self_disallowed.php
|
<?hh // strict
class C {
<<__LSB>> private static int $id = 0;
public static function foo(): int {
return self::$id;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_this.php
|
<?hh // strict
<<__ConsistentConstruct>>
class C {
<<__LSB>> private static ?this $instance = null;
public static function get(): this {
if (static::$instance === null) {
static::$instance = new static();
}
return static::$instance;
}
}
class D extends C {
public static function get2(): D {
return self::get();
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lsb_this_in_generic.php
|
<?hh // strict
class A {
<<__LSB>> private static vec<this> $v = vec[];
public static function foo(): vec<this> {
return static::$v;
}
}
class B extends A {
}
class C extends B {
}
class D {
public static function bar(): void {
self::baz(A::foo());
self::qux(B::foo());
}
private static function baz(vec<A> $a): void {
}
private static function qux(vec<B> $b): void {
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/ltgt.php
|
<?hh
function f(?int $x): void {
if ($x !== null) {
expect_int($x);
}
}
function expect_int(int $y): void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lvalue_foreach.php
|
<?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
function my_example(darray<int, int> $items): void {
$x = null as dynamic;
foreach ($items as $x::foo) {
}
}
<<__EntryPoint>>
function main():void {
my_example(darray[2 => 3, 4 => 5]);
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/lvar_in_obj_get.php
|
<?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
function test(string $f, string $g): void {
/* HH_FIXME[4009] */
$x = $f();
$x->$g();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/map.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 {
$x = Map { 'f' => 'foo', 'b' => 'bar' };
$y = Map { 0 => 'foo', 10 => 'bar' };
$x['f'] = 'f';
$y[0] = 'f';
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/map_foreach.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.
*
*
*/
// TODO: Fix A<T> as A
//
//function foo1(Map $map) {
// foreach ($map as $v) {
// f2($v);
// }
// $map[] = 'meh';
// $map[10] = 'meh';
// f2($map[10]);
//}
//function foo2(Map $map) {
// foreach ($map as $k => $v) {
// f1($k);
// f2($v);
// }
//}
function foo3(Map<int, string> $map): void {
foreach ($map as $v) {
f2($v);
}
// $map[] = 'meh';
// $map[10] = 'meh';
f2($map[10]);
}
function foo4(Map<int, string> $map): void {
foreach ($map as $k => $v) {
f1($k);
f2($v);
}
}
function f1(int $k): void {}
function f2(string $v): void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/map_interfaces.php
|
<?hh
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the "hack" directory of this source tree.
*
*
*/
interface A {}
// until we find something better
class CNull {
const ?A A = null;
}
class B implements A {}
class C implements A {}
class D {
protected Map<string, A> $x;
public function __construct() {
$this->x = Map{};
}
public function foo(): void {
$y = CNull::A;
if (true) {
$y = new B();
} else {
$y = new C();
}
if($y) {
$this->x['meh'] = $y;
}
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/map_non_static.php
|
<?hh // strict
function get(): string {
return 'hello';
}
class Foo {
public Map<int, string> $vec = Map { 3 => get(), 4 => 'world' };
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/massive_type.php
|
<?hh
type A = shape('a1' => int, 'a2' => int);
type B = shape('b1' => A, 'b2' => A);
type C = shape('c1' => B, 'c2' => B);
type D = shape('d1' => C, 'd2' => C);
type E = shape('e1' => D, 'e2' => D);
type F = shape('f1' => E, 'f2' => E);
type G = shape('g1' => F, 'g2' => F);
type H = shape('h1' => G, 'h2' => G);
type I = shape('i1' => H, 'i2' => H);
type J = shape('j1' => I, 'j2' => I);
type K = shape('k1' => J, 'k2' => J);
type L = shape('l1' => K, 'l2' => K);
type M = shape('m1' => L, 'm2' => L);
type N = shape('n1' => M, 'n2' => M);
function f(N $a): void {
g($a);
}
function g(int $_): void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/math_operator.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 {
// Integer Operations
$a = 1;
$b = 2;
$c = $a + $b;
$c = $a - $b;
$c = $a * $b;
$c = $a % $b;
$c = - $a;
$c += $a;
$c -= $a;
$c *= $a;
$c %= $a;
++$c;
$c++;
--$c;
$c--;
$c = $a ** $b;
// Bitwise Operators
$c = $a ^ $b;
$c = $a & $b;
$c = $a | $b;
$c = $a << $b;
$c = $a >> $b;
$c &= $b;
$c |= $b;
$c <<= $b;
$c >>= $b;
// Boolean Operators
$e = false;
$f = true;
$str = "1";
$d = ($a == $b);
$d = ($a != $b);
// $d = ($a <> $b);
$d = ($a !== $b);
$d = ($a === $b);
$d = ($a < $b);
$d = ($a > $b);
$d = ($a <= $b);
$d = ($a >= $b);
$d = !$e;
$d = $a && $b;
$d = $a || $b;
// Spaceship operator
$i = $a <=> $b;
// Float operations
$float_1 = 4.0;
$float_2 = 3.0;
$float_3 = $float_1/$float_2;
$float_3 /= $float_1;
$float_4 = $float_1 ** $float_3;
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/member_varname.php
|
<?hh
class A {
protected int $val = 43;
public function b(): int {
return $this->val - 1;
}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/memoize_obj_policied.php
|
<?hh
class Foo implements IMemoizeParam {
public function getInstanceKey()[] : string {
return "";
}
}
class Bar implements UNSAFESingletonMemoizeParam {
public function getInstanceKey()[] : string {
return "";
}
}
<<__Memoize>>
function foo(vec<int> $x)[] : void {}
<<__Memoize>>
function not_ok(vec<Foo> $x)[] : void {}
<<__Memoize>>
function ok_singleton(Bar $x)[] : void {}
<<__Memoize>>
function ok_vec_singleton(vec<Bar> $x)[] : void {}
<<__Memoize>>
function not_ok_vector_singleton(Vector<Bar> $x)[] : void {}
<<__Memoize>>
function not_ok_mixed(mixed $x)[] : void {}
<<__Memoize>>
function not_ok_vector(Vector<int> $x)[] : void {}
<<__Memoize>>
function not_ok2(vec<Foo> $x)[write_props] : void {}
<<__Memoize>>
function ok(vec<Foo> $x) : void {}
<<__Memoize>>
function ok2(vec<Foo> $x)[globals] : void {}
<<__Memoize>>
function not_ok_policied(vec<Foo> $x)[zoned] : void {}
<<__Memoize(#KeyedByIC)>>
function ok_policied(vec<Foo> $x)[zoned] : void {}
|
PHP
|
hhvm/hphp/hack/test/typecheck/message_vector.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 {}
class B extends A {}
function foobar2(Vector<B> $x): void {}
function foobar1(): void {
$v = Vector {};
$v[] = new B();
foobar2($v);
$v[] = new A();
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_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.
*
*
*/
/**
* 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 {}
public static function test2(): void {
A::f2();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_02.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 {}
public static function test2(): void {
C::f4();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_03.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 {}
public static function test2(): void {
parent::f2();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_04.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 {}
public static function test2(): void {
self::f2();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_05.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 {}
public static function test2(): void {
static::f2();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_08.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 {}
public static function test2(A $x): void {
$x->f2();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_09.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 {}
public static function test2(A $x): void {
$x::f2();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_10.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 {}
public static function test2(): void {
A::f1();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_11.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 {}
public static function test2(): void {
C::f3();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_12.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 {}
public static function test2(): void {
parent::f1();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_13.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 {}
public static function test2(): void {
self::f1();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_14.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 {}
public static function test2(): void {
static::f1();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_17.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 {}
public static function test2(A $x): void {
$x->f1();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_18.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 {}
public static function test2(A $x): void {
$x::f1();
}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_19.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 {
A::f2();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_20.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 {
C::f4();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_21.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 {
parent::f2();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_22.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 {
self::f2();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_23.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 {
static::f2();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_24.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->f2();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_25.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::f2();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_26.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->f2();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_27.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::f2();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_28.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 {
A::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_29.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 {
C::f3();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
PHP
|
hhvm/hphp/hack/test/typecheck/method_dispatch_30.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 {
parent::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_31.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 {
self::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_32.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 {
static::f1();
}
public static function test2(): void {}
}
class C {
public function f3(): void {}
public static function f4(): void {}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.