language
stringlengths 0
24
| filename
stringlengths 9
214
| code
stringlengths 99
9.93M
|
---|---|---|
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/return_like_enforced.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
// No SDT
function get(): ~vec<int> { return vec[3]; }
<<__SupportDynamicType>>
function get(): ~vec<vec<int>> { return vec[vec[3]]; }
<<__SupportDynamicType>>
function test(~int $x):vec<int> {
$y = get()[$x];
return $y;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/return_like_enforced.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
function get(): ~vec<int> { return vec[3]; }
<<__SupportDynamicType>>
function test(~int $x):int {
$y = get()[$x];
return $y;
}
<<__SupportDynamicType>>
async function test2(~int $x):Awaitable<int> {
$y = get()[$x];
return $y;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/return_value_1.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class C<T> {}
class E {}
<<__SupportDynamicType>>
class D {
public function foo(C<int> $x): ?E { return null; }
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/ret_nonsdt.bad.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
class A { }
<<__SupportDynamicType>>
function foo(vec<int> $vi):A {
return new A();
}
<<__SupportDynamicType>>
function testlam():void {
$f = (int $x) : A ==> { return new A(); };
$g = (int $x) ==> { return new A(); /*hh_show_env();*/ };
$h = (vec<int> $x) ==> { return new A(); };
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sdt_call_infer_like.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
function expect<T as supportdyn<mixed> >(T $obj, mixed ...$args)[]: ~ExpectObj<T> {
throw new Exception("A");
}
<<__SupportDynamicType>>
final class ExpectObj<T as supportdyn<mixed> > {
final public function toBeGreaterThan(num $expected): void where T as num {
}
}
function getVec():~vec<int> { return vec[]; }
function testit():void {
$y = getVec()[0];
// This works
$z = expect<int>($y);
$z->toBeGreaterThan(0);
// This does not, because we infer ~int for the type argument
// This is due to the call to expect generating ~int <: #0 <: supportdyn<mixed>
$w = expect($y);
$w->toBeGreaterThan(0);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sdt_check_nullable_container.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
final class C {
public async function genData(
): Awaitable<~this::TC> {
throw new Exception("A");
}
const type TC = shape('a' => vec<int>);
private ~?this::TC $data = null;
public async function genSomething(vec<int> $v): Awaitable<~vec<int>> {
$this->data = await $this->genData();
return $this->data['a'];
}
}
<<__SupportDynamicType>>
final class D {
public ?~vec<int> $p = null;
public function appendSomething(vec<int> $v): void {
$this->p ??= vec[];
$this->p[] = 5;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sdt_dynamic_check.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
interface I { }
<<__SupportDynamicType>>
class C implements I { }
<<__SupportDynamicType>>
function toplevel1(int $x):I {
// Should only appear once
hh_show($x);
return new C();
}
<<__SupportDynamicType>>
function toplevel2(vec<C> $x):I {
// Should appear twice
hh_show($x);
return $x[0];
}
<<__SupportDynamicType>>
async function toplevel3(int $x):Awaitable<I> {
// Should only appear once
hh_show($x);
return new C();
}
<<__SupportDynamicType>>
async function toplevel4(vec<C> $x):Awaitable<I> {
// Should appear twice
hh_show($x);
return $x[0];
}
<<__SupportDynamicType>>
class SD {
public function meth1(int $x):I {
// Should only appear once
hh_show($x);
return new C();
}
public function meth2(vec<C> $x):I {
// Should appear twice
hh_show($x);
return $x[0];
}
public async function meth3(int $x):Awaitable<I> {
// Should only appear once
hh_show($x);
return new C();
}
public async function meth4(vec<C> $x):Awaitable<I> {
// Should appear twice
hh_show($x);
return $x[0];
}
}
<<__SupportDynamicType>>
function lambdatest(int $z):void {
// Should only appear once
$f1 = (int $x) ==> { hh_show($x); return new C(); };
// Should appear twice
$f2 = (vec<C> $x) ==> { hh_show($x); return $x[0]; };
// Should only appear once
$f3 = async (int $x) ==> { hh_show($x); return new C(); };
// Should appear twice
$f4 = async (vec<C> $x) ==> { hh_show($x); return $x[0]; };
// Should only appear once
$f5 = (int $x):I ==> { hh_show($x); return new C(); };
// Should only appear once
$f6 = async (int $x):Awaitable<I> ==> { hh_show($x); return new C(); };
}
<<__SupportDynamicType, __ConsistentConstruct>>
abstract class CC<TE as supportdyn<mixed> > {
final public static function delegateNew(
): ~supportdyn<(function(): ~CC<TE>)> {
$class_name = static::class;
return () ==> (new $class_name());
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sdt_lambda.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<file:__EnableUnstableFeatures('upcast_expression')>>
// Not SDT
class C { }
// Explicit SDT lambda, unenforced explicit parameter type
function explicit_nonenforced_nondynamic():void {
$f = <<__SupportDynamicType>> (vec<C> $x) ==> new C();
}
<<__SupportDynamicType>>
class D { }
<<__SupportDynamicType>>
class E {
public function foo():D { return new D(); }
}
function expectD(D $n):void { }
function testit():void {
$f = <<__SupportDynamicType>> (vec<E> $v):D ==> {
$x = $v[0]->foo();
// should be an error in check under dynamic
expectD($x);
return $x;
};
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sdt_lambda.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<file:__EnableUnstableFeatures('upcast_expression')>>
function expectSupportDynamic(supportdyn<nonnull> $_):void { }
function expectDynamic(dynamic $_):void { }
function expectPrecise<T1,T2>((function(T1):T2) $_):void { }
function expectLike<T1,T2>(~(function(T1):T2) $_):void { }
// Explicit SDT lambda, enforced parameter type
function explicit_sdt_enforced():void {
$f = <<__SupportDynamicType>> (int $x) ==> true;
expectSupportDynamic($f);
expectDynamic($f upcast dynamic);
expectPrecise<int,bool>($f);
expectLike<int,bool>($f);
}
// Implicit SDT lambda, enforced parameter type
<<__SupportDynamicType>>
function implicit_sdt_enforced():void {
$f = (int $x) ==> true;
expectSupportDynamic($f);
expectDynamic($f upcast dynamic);
expectPrecise<int,bool>($f);
expectLike<int,bool>($f);
}
function intpred(int $x):bool { return false; }
// Implicit SDT lambda, inferred return type
<<__SupportDynamicType>>
function implicit_inferred():void {
$f = (int $x) ==> intpred($x);
expectSupportDynamic($f);
expectDynamic($f upcast dynamic);
expectPrecise<int,bool>($f);
expectLike<int,bool>($f);
}
// Explicit SDT lambda, unenforced explicit parameter type
function explicit_nonenforced():void {
$f = <<__SupportDynamicType>> (vec<int> $x) ==> $x[0];
expectSupportDynamic($f);
expectDynamic($f upcast dynamic);
expectPrecise<vec<int>,int>($f);
expectLike<vec<int>,int>($f);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sdt_lambda.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
class D { }
<<__SupportDynamicType>>
class C {
public function foo():D { return new D(); }
}
function expectD(D $n):void { }
function testit():void {
$f = <<__SupportDynamicType>> (vec<C> $c):D ==> {
$x = $c[0]->foo();
// should be an error in check under dynamic
expectD($x);
return $x;
};
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sdt_private_method.bad.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
class A {
const type TC = int;
}
<<__SupportDynamicType>>
class C {
private A::TC $prop = 5;
private function set(A::TC $vi):void {
// This should be rejected
$this->prop = $vi;
}
public function breakit(dynamic $d):void {
$d->set("A");
}
public function get():int {
return $this->prop;
}
}
<<__EntryPoint>>
function main():void {
$c = new C();
$c->breakit($c);
$x = $c->get();
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sd_shape_update.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
type TS = supportdyn<shape('a' => int, ...)>;
<<__SupportDynamicType>>
function expectShape(~TS $_):void { }
<<__SupportDynamicType>>
function getShape():~TS {
return shape('a' => 3);
}
<<__SupportDynamicType>>
function testit():void {
$x = getShape();
$x['a'] = 3;
expectShape($x);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/set_append.bad.php | <?hh
function test(dynamic $d, Set<int> $s) : void {
$s[] = $d;
hh_expect_equivalent<Set<int>>($s);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/set_append.good.php | <?hh
function test(dynamic $d, Set<arraykey> $s) : void {
$s[] = $d;
hh_expect_equivalent<Set<arraykey>>($s);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/set_create.good.php | <?hh
function test_create_dyn_idx(dynamic $d) : Set<(~int & arraykey)> {
Set<arraykey>{$d, 1};
$x = Set{$d, 1};
hh_expect_equivalent<Set<(~int & arraykey)>>($x);
return Set{$d, 1};
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/shapes_subtyping.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
type TS1 = supportdyn<shape(
'foo' => int,
...
)>;
type TS2 = supportdyn<shape(
'foo' => int,
?'bar' => mixed,
...
)>;
type TS3 = supportdyn<shape(
'foo' => int,
?'bar' => supportdyn<mixed>,
...
)>;
type TS4 = shape('foo' => int, ?'bar' => supportdyn<mixed>);
type TS5 = supportdyn<shape('foo' => int, 'bar' => mixed)>;
function expect1(TS1 $_):void { }
function expect2(TS2 $_):void { }
function expect3(TS3 $_):void { }
function expect4(TS4 $_):void { }
function testit(TS1 $x, TS2 $y, TS3 $z, TS4 $w, TS5 $v):void {
expect1($x); expect1($y); expect1($z); expect1($w);
expect2($x); expect2($y); expect2($z); expect2($w);
expect3($x); expect3($y); expect3($z); expect3($w);
expect4($v);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/shapes_to_collection.good.php | <?hh
function test1(shape('a' => int, 'b' => float) $s1, supportdyn<shape('a' => int, 'b' => float, ...)> $s2):void {
$df = Shapes::toDict<>;
$af = Shapes::toArray<>;
$d1 = Shapes::toDict($s1);
$d2 = Shapes::toDict($s2);
$d3 = ($df)($s2);
$a1 = Shapes::toArray($s1);
$a2 = Shapes::toArray($s2);
$a3 = ($af)($s2);
hh_expect_equivalent<dict<string,num>>($d1);
hh_expect_equivalent<dict<arraykey,supportdyn<mixed>>>($d2);
// Signature in hhi doesn't include supportdyn unless pessimised
hh_expect_equivalent<dict<arraykey,mixed>>($d3);
hh_expect_equivalent<darray<string,num>>($a1);
hh_expect_equivalent<darray<arraykey,supportdyn<mixed>>>($a2);
// Signature in hhi doesn't include supportdyn unless pessimised
hh_expect_equivalent<darray<arraykey,mixed>>($a3);
}
function test2<T1 as shape('a' => int, 'b' => float), T2 as supportdyn<shape('a' => int, 'b' => float, ...)>>(T1 $s1, T2 $s2):void {
$d1 = Shapes::toDict($s1);
$d2 = Shapes::toDict($s2);
$a1 = Shapes::toArray($s1);
$a2 = Shapes::toArray($s2);
hh_expect_equivalent<dict<string,num>>($d1);
hh_expect_equivalent<dict<arraykey,supportdyn<mixed>>>($d2);
hh_expect_equivalent<darray<string,num>>($a1);
hh_expect_equivalent<darray<arraykey,supportdyn<mixed>>>($a2);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/shape_indexing.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
function myfilter<Tv as supportdyn<mixed> >(
~Traversable<Tv> $traversable,
~?supportdyn<(function (Tv): ~bool)> $value_predicate = null,
): ~vec<Tv> {
return vec[];
}
type TS = supportdyn<shape(
'score' => float,
...
)>;
<<__SupportDynamicType>>
function test(
~vec<TS> $v,
bool $b,
): ~float {
$e = null;
$v = myfilter(
$v, $w ==> $w['score'] > 0,
);
if ($b) {
$e = $v[0];
}
if ($e === null) {
return 0.0;
}
return $e['score'];
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/shape_union.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
function expectSD(supportdyn<mixed> $m):void { }
function test1(supportdyn<shape(?'a' => int, ...)> $s, supportdyn<shape('b' => bool, ...)> $t, bool $b):void {
if ($b) $s = $t;
$x = Shapes::idx($s,'a');
expectSD($x);
}
function test2(shape(?'a' => int) $s, supportdyn<shape('b' => bool, ...)> $t, bool $b):void {
if ($b) $s = $t;
$x = Shapes::idx($s,'a');
expectSD($x);
}
function test3(shape(?'a' => int) $s, supportdyn<shape('b' => bool, ...)> $t, bool $b):void {
if ($b) $t = $s;
$x = Shapes::idx($t,'a');
expectSD($x);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/shape_update_nonsdt.good.php | <?hh
class NonSDT { }
function expectDyn(dynamic $_):void { }
function test1(supportdyn<shape('a' => int, ...)> $s):void {
expectDyn($s);
// Update just the 'a' field with non-sd type
$s['a'] = new NonSDT();
// So 'b' field should support dynamic
expectDyn(Shapes::idx($s, 'b'));
// Now restore 'a' field
$s['a'] = 3;
expectDyn($s);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sound_dynamic_callable_1.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class Box<T> {
public function __construct(public T $x) {}
}
<<__SupportDynamicType>>
class C {
<<__SupportDynamicType>>
public function foo() : Box<int> {
return new Box(42);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sound_dynamic_callable_2.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class Box<T> {
public function __construct(public T $x) {}
}
class C {
<<__SupportDynamicType>>
public function foo() : Box<int> {
return new Box(42);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sound_dynamic_callable_3.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<file:__EnableUnstableFeatures('upcast_expression')>>
class C {
<<__SupportDynamicType>>
public function foo(vec<int> $x):int {
$x upcast vec<int>;
return $x[0];
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sound_dynamic_callable_4.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class Evil<T> {}
class A<T> {}
class B extends A<int> {}
class C {
public function expect_A(A<int> $a) : void {}
}
<<__SupportDynamicType>>
class Foo {
public function foo(Evil<int> $x, B $a) : void {
(new C())->expect_A($a);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/static_sdt.good.php | <?hh
<<__SupportDynamicType>>
class A<+T as supportdyn<mixed> > {
public function __construct(private ~T $x) {}
}
<<__SupportDynamicType>>
function get(): ~C { return new C(); }
<<__SupportDynamicType>>
class C {
public function gen(): A<~?string> {
return new A("");
}
}
<<__SupportDynamicType>>
class S {
public static function remA<T as supportdyn<mixed> >(A<~T> $a): ~T {
throw new Exception();
}
}
<<__SupportDynamicType>>
function remA2<T as supportdyn<mixed> >(A<~T> $a): ~T { throw new Exception(); }
<<__SupportDynamicType>>
function getMessage(): void {
$x = get();
$y = $x->gen();
remA2($y);
S::remA($y);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/stringish_intish_refinement.bad.php | <?hh
enum E: string {
MEANING = "42";
}
function takes_e(E $_): void {}
function test_opaque_is_stringish(): void {
$e = 42;
if ($e is E) {
takes_e($e);
}
$e = "42";
if ($e is E) {
takes_e($e);
}
}
function test_opaque_as_stringish(): void {
$e = 42 as E;
takes_e($e);
$e = "42" as E;
takes_e($e);
}
enum F: string as string {
MEANING = "42";
}
function takes_f(F $_): void {}
function test_transparent_is_stringish(): void {
$e = 42;
if ($e is F) {
takes_f($e);
}
$e = "42";
if ($e is F) {
takes_f($e);
}
}
function test_transparent_as_stringish(): void {
$e = 42 as F;
takes_f($e);
$e = "42" as F;
takes_f($e);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/stringish_intish_refinement.good.php | <?hh
enum G: arraykey {
MEANING = "42";
}
function takes_g(G $_): void {}
function test_opaque_is_arraykeyish(): void {
$e = 42;
if ($e is G) {
takes_g($e);
}
$e = "42";
if ($e is G) {
takes_g($e);
}
}
function test_opaque_as_arraykeyish(): void {
$e = 42 as G;
takes_g($e);
$e = "42" as G;
takes_g($e);
}
enum H: arraykey as arraykey {
MEANING = "42";
}
function takes_h(H $_): void {}
function test_transparent_is_arraykeyish(): void {
$e = 42;
if ($e is H) {
takes_h($e);
}
$e = "42";
if ($e is H) {
takes_h($e);
}
}
function test_transparent_as_arraykeyish(): void {
$e = 42 as H;
takes_h($e);
$e = "42" as H;
takes_h($e);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/stringish_intish_refinement_arraykey_bound.good.php | <?hh
function takes_arraykey(arraykey $_): void {}
enum E: string {}
function main(): void {
$e = 42 as E; // : ~E & arraykey
// The following two typecheck due to the & arraykey part of $e's type.
takes_arraykey($e);
keyset(vec[$e]);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/subtype_supportdynamic.bad.php | <?hh
function e(supportdyn<nonnull> $sd): void {}
class C {}
function test_prim(mixed $m, nonnull $nn, C $c): void {
e($m);
e($nn);
e($c);
}
function test_contain((string, C) $t, vec<C> $v, dict<string, C> $di,
darray<arraykey, C> $da,
varray<C> $va): void {
e($t);
e($v);
e($di);
e($da);
e($va);
}
function test_shape(shape('x' => int, ?'y' => vec<C>) $s): void {
e($s);
}
function test_container_context(vec<C> $v,
dict<int, C> $d,
darray<arraykey, C> $da,
varray<C> $va): void {
e($v);
e($d);
}
function test_shape_context(shape('x' => int, ?'y' => C) $s): void {
e($s);
}
class V1<<<__RequireDynamic>> T> {};
class V2<<<__RequireDynamic>> +T> {};
function test_class_context(V1<int> $v1, V2<C> $v2): void {
e($v1);
e($v2);
}
function test_union(int $i, C $c, bool $b): void {
if ($b) {
$x = $i;
} else {
$x = $c;
}
e($x);
}
function test_null_things(null $n, ?int $ni): void {
e($n);
e($ni);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/subtype_supportdynamic.good.php | <?hh
function expectNonNull(nonnull $nn):void { }
function e(supportdyn<nonnull> $sd): void {
expectNonNull($sd);
}
<<__SupportDynamicType>>
class C {}
enum E1: int {
CONST1 = 1;
}
enum E2: int as int {
CONST2 = 2;
}
enum E3: string {
CONST3 = "a";
}
enum E4: string as string {
CONST4 = "b";
}
function test_enum_type(E4 $e) : void {
e($e);
}
function test_prim(bool $b, int $i, float $f, num $n, string $s, arraykey $ak)
: void {
e($b);
e($i);
e($f);
e($n);
e($s);
e(new C());
e($ak);
e(E1::CONST1);
e(E2::CONST2);
e(E3::CONST3);
e(E4::CONST4);
}
function test_contain((string, int) $t, vec<int> $v, dict<string, int> $di,
keyset<arraykey> $ks, darray<arraykey, vec<C>> $da,
varray<int> $va): void {
e($t);
e($v);
e($di);
e($ks);
e($da);
e($va);
}
function test_shape(shape('x' => int, ?'y' => vec<C>) $s): void {
e($s);
}
<<__SupportDynamicType>>
class D<T> {}
<<__SupportDynamicType>>
class E {}
function test_class(C $c, D<int> $di, D<E> $de): void {
e($c);
e($di);
e($de);
}
function test_container_context(vec<int> $v,
dict<int, C> $d): void {
e($v);
e($d);
}
function test_shape_context(shape('x' => int, ?'y' => vec<C>) $s): void {
e($s);
}
function test_union(int $i, C $c, bool $b): void {
if ($b) {
$x = $i;
} else {
$x = $c;
}
e($x);
}
function test_inter(int $i, bool $b): void {
if ($i is E) {
e($i);
}
}
<<__SupportDynamicType>>
function foo(int $x):bool {
return false;
}
function test_function((function(~int):bool) $f): void {
e($f);
e(foo<>);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sub_function_type_dynamic.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<file:__EnableUnstableFeatures('upcast_expression')>>
class C { }
function test1(
(function(int):int) $f1,
(function(mixed, dynamic):mixed) $f2,
(function():vec<mixed>) $f3,
(function():C) $f4):void {
$f1 upcast dynamic;
$f2 upcast dynamic;
$f3 upcast dynamic;
$f4 upcast dynamic;
((int $x) ==> $x+1) upcast dynamic;
($x ==> new C()) upcast dynamic;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/sub_function_type_dynamic.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
class C { }
<<__SupportDynamicType>>
function foo(int $_):bool {
return false;
}
function expectFun((function(int):bool) $_):void { }
function test1(
(function(dynamic):int) $f1,
(function(mixed, dynamic):string) $f2,
(function((string|dynamic),dynamic...):float) $f3,
(function():void) $f4,
(function():C) $f5):void {
$f1 upcast dynamic;
$f2 upcast dynamic;
$f3 upcast dynamic;
$f4 upcast dynamic;
$f5 upcast dynamic;
($x ==> $x) upcast dynamic;
((dynamic $d) ==> $d->foo()) upcast dynamic;
foo<> upcast dynamic;
expectFun(foo<>);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn.bad.php | <?hh
class C {
const type T = supportdyn<nonnull>;
}
function expr(supportdyn<nonnull> $sd): void {
$sd[0];
$sd[] = 0;
$sd::f();
$sd->m();
$sd?->m();
$sd->p;
$sd?->p;
'str'.$sd;
$sd + 1;
}
async function stmt(supportdyn<nonnull> $sd): Awaitable<void> {
foreach ($sd as $_) {}
foreach ($sd as $_k => $_v) {}
await $sd;
}
type N = supportdyn<nonnull>;
function access_typeconst(N::C $_): void {}
function cname(classname<supportdyn<nonnull>> $_): void {}
enum E: supportdyn<nonnull> {}
function expectDyn(dynamic $d):void { }
function test1(supportdyn<mixed> $sd):void {
expectDyn($sd);
}
function voidfun():void { }
function void_to_supportdyn():supportdyn<nonnull> {
return voidfun();
}
function ignore_supportdyn(mixed $m):supportdyn<nonnull> {
return $m as C::T;
}
function expectSupportDynNonNull(supportdyn<nonnull> $_):bool {
return false;
}
function ignore_supportdyn_2(mixed $m):bool {
return $m is C::T && expectSupportDynNonNull($m);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn.good.php | <?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
class C {
const type T = supportdyn<nonnull>;
}
<<__SupportDynamicType>>
class D extends C { }
<<__SupportDynamicType>>
class A { }
function expectNonNull(nonnull $nn):bool {
return false;
}
function expectSupportDynNonNull(supportdyn<nonnull> $sd): bool {
return expectNonNull($sd);
}
function expr(supportdyn<mixed> $sd): void {
$sd === 1;
}
function stmt(\HH\supportdyn<mixed> $sd): void {
if ($sd) {}
switch ($sd) {
case 42:
break;
}
}
function test1(D $d, C $c):void {
expectSupportDynNonNull($d);
}
function test2(supportdyn<mixed> $sd):dynamic {
return $sd upcast dynamic;
}
function test3(supportdyn<mixed> $sd):?supportdyn<nonnull> {
return $sd;
}
function expectTrav<T as supportdyn<nonnull>>(Traversable<?T> $_):void { }
function test4(vec<supportdyn<mixed>> $v):void {
expectTrav($v);
}
function voidfun():void { }
function callvoid():supportdyn<mixed> {
return voidfun();
}
function returnunion(bool $b):supportdyn<nonnull> {
return $b ? new A() : new D();
}
function test_as(mixed $m):nonnull {
return $m as C::T;
}
function test_is(mixed $m):bool {
return $m is C::T && expectNonNull($m);
}
function test_as_2(supportdyn<mixed> $m): supportdyn<nonnull> {
return $m as C::T;
}
function test_is_2(supportdyn<mixed> $m): bool {
return $m is C::T && expectSupportDynNonNull($m);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdynamic.bad.php | <?hh
function expr(supportdyn<nonnull> $sd): void {
$sd[0];
$sd[] = 0;
$sd::f();
$sd->m();
$sd?->m();
$sd->p;
$sd?->p;
'str'.$sd;
$sd + 1;
}
async function stmt(supportdyn<nonnull> $sd): Awaitable<void> {
foreach ($sd as $_) {}
foreach ($sd as $_k => $_v) {}
await $sd;
}
type N = supportdyn<nonnull>;
function access_typeconst(N::C $_): void {}
function cname(classname<supportdyn<nonnull>> $_): void {}
enum E: supportdyn<nonnull> {}
function targs(supportdyn<nonnull, int> $_): void {} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdynamic.good.php | <?hh
function expr(supportdyn<nonnull> $sd): void {
$sd === 1;
}
function stmt(supportdyn<nonnull> $sd): void {
if ($sd) {}
switch ($sd) {
case 42:
break;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdynamic_intersection.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
class C { }
function returnSD(?C $c): C {
if ($c is nonnull) {
return $c;
}
else return new C();
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_compare.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
function foo(
~supportdyn<shape('a' => int, ...)> $s,
~?int $y = null,
): ~bool {
$x = $s['a'];
$y ??= $s['a'];
return 3 <= $y;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_function.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
function foo(int $x):bool {
return $x === 3;
}
function expectSDfun(supportdyn<(function(int):bool)> $f):void { }
function expectFun((function(int):bool) $f):void { }
function expectLikeSDfun(~supportdyn<(function(int):bool)> $f):void { }
function test1():void {
expectSDfun(foo<>);
expectLikeSDfun(foo<>);
expectFun(foo<>);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_function_call.good.php | <?hh
class C {}
<<__SupportDynamicType>>
function g(vec<int> $vi, vec<string> $vs): bool {
return false;
}
<<__SupportDynamicType>>
function h(vec<C> $vi, vec<string> $vs): bool {
return false;
}
function f(
~vec<int> $x,
~vec<string> $y,
dynamic $d,
vec<int> $z,
vec<string> $w,
vec<C> $c,
): ~bool {
$r1 = g($x, $y);
hh_expect_equivalent<~bool>($r1);
$r2 = g($d, $y);
hh_expect_equivalent<~bool>($r2);
$r3 = g($z, $y);
hh_expect_equivalent<~bool>($r3);
$r4 = g($z, $w);
hh_expect_equivalent<bool>($r4);
$r5 = h($c, $w);
hh_expect_equivalent<bool>($r5);
return $r1;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_ho_run.bad.php | <?hh
class C {}
function f(
~vec<int> $x,
~vec<string> $y,
vec<string> $y2,
~vec<C> $c,
supportdyn<(function(vec<int>, vec<string>): bool)> $g,
supportdyn<(function(vec<C>, vec<string>): bool)> $h,
supportdyn<mixed> $m,
): void {
$g($x, $x);
$g($x);
$h($c, $y);
$h($c, $y2);
$m($c);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_ho_run.good.php | <?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
class C {}
function f(
~vec<int> $x,
~vec<string> $y,
dynamic $d,
vec<int> $z,
vec<string> $w,
vec<C> $c,
supportdyn<(function(vec<int>, vec<string>): bool)> $g,
supportdyn<(function(vec<C>, vec<string>): bool)> $h,
supportdyn<mixed> $m,
): ~bool {
$r1 = $g($x, $y);
hh_expect_equivalent<~bool>($r1);
$r2 = $g($d, $y);
hh_expect_equivalent<~bool>($r2);
$r3 = $g($z, $y);
hh_expect_equivalent<~bool>($r3);
$r4 = $g($z, $w);
hh_expect_equivalent<bool>($r4);
$r5 = $h($c, $w);
hh_expect_equivalent<bool>($r5);
$r6 = ($m upcast dynamic)(1);
hh_expect_equivalent<dynamic>($r6);
return $r1;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_pushing.bad.php | <?hh
function takes_iter(Iterator<supportdyn<mixed>> $kc) : void {}
function takes_kiter(KeyedIterator<arraykey, supportdyn<mixed>> $kc)
: void {}
function f(supportdyn<Iterator<mixed>> $i) : void {
takes_iter($i);
}
function g(supportdyn<KeyedIterator<arraykey, mixed>> $ki) : void {
takes_kiter($ki);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_pushing.good.php | <?hh
function takes_container(Container<supportdyn<mixed>> $kc) : void {}
function takes_kcontainer(KeyedContainer<arraykey, supportdyn<mixed>> $kc)
: void {}
function takes_trav(Traversable<supportdyn<mixed>> $kc) : void {}
function takes_ktrav(KeyedTraversable<arraykey, supportdyn<mixed>> $kc)
: void {}
function f(supportdyn<vec<mixed>> $m,
supportdyn<KeyedContainer<arraykey, mixed>> $c,
supportdyn<Iterator<mixed>> $i)
: vec<supportdyn<mixed>> {
takes_container($m);
takes_trav($m);
takes_container($c);
takes_trav($c);
takes_trav($i);
return $m;
}
function g(supportdyn<dict<arraykey, mixed>> $m,
supportdyn<KeyedContainer<arraykey, mixed>> $kc,
supportdyn<KeyedIterator<arraykey, mixed>> $ki) :
dict<arraykey, supportdyn<mixed>> {
takes_kcontainer($m);
takes_kcontainer($kc);
takes_ktrav($m);
takes_ktrav($kc);
takes_ktrav($ki);
return $m;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_push_as.good.php | <?hh
function my_reduce<Tv as supportdyn<mixed>, Ta as supportdyn<mixed>>(
Traversable<Tv> $traversable,
(function(Ta, Tv): Ta) $accumulator,
Ta $initial,
) : Ta {
return $initial;
}
function f(supportdyn<vec<mixed>> $p): void {
my_reduce(
$p,
($result, $cp) ==> {
$x = $cp as KeyedContainer<_, _>;
$result[] = (string)idx($x, 'x');
return $result;
},
vec[]);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_refinement.good.php | <?hh
function expect_trav_sd(Traversable<supportdyn<mixed>> $m) : void {}
function expect_kc_sd(KeyedContainer<arraykey, supportdyn<mixed>> $m) : void {}
function expect_vec_sd(vec<supportdyn<mixed>> $m) : void {}
function f<T as supportdyn<mixed>>(supportdyn<mixed> $m, T $t) : void {
if ($m is Traversable<_>) {
expect_trav_sd($m);
}
else if ($m is KeyedContainer<_, _>) {
expect_kc_sd($m);
}
else if ($m is vec<_>) {
expect_vec_sd($m);
}
if ($t is Traversable<_>) {
expect_trav_sd($t);
}
else if ($t is KeyedContainer<_, _>) {
expect_kc_sd($t);
}
else if ($t is vec<_>) {
expect_vec_sd($t);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_shape.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
function expectNullableInt(?int $_):void { }
function expectSDshape(supportdyn<shape('a' => int, ...)> $s):int {
$x = $s['a'];
$y = Shapes::idx($s, 'a');
expectNullableInt($y);
return $x;
}
function test2(shape('a' => int) $s):void {
expectSDshape($s);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_shapes_idx.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class C { }
<<__SupportDynamicType>>
class D extends C { }
type TS = supportdyn<shape('a' => int, ?'b' => int, 'c' => C, ?'d' => supportdyn<C>, ...)>;
function expectSDC(supportdyn<C> $x):void { }
function foo(TS $s):void {
// This shold be rejected because the result of the idx
// can be C, which is not supportdyn
expectSDC(Shapes::idx($s, 'd', new C()));
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_shapes_idx.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class C { }
<<__SupportDynamicType>>
class D extends C { }
type TS = supportdyn<shape('a' => int, ?'b' => int, 'c' => C, ?'d' => supportdyn<C>, ...)>;
function expectSDNC(?supportdyn<C> $x):void { }
function expectSDC(supportdyn<C> $x):void { }
function expectSDM(supportdyn<mixed> $x):void { }
function expectShape(shape('c' => supportdyn<C>, ...) $_):void { }
function foo(TS $s):void {
expectSDNC(Shapes::idx($s, 'c'));
expectSDM(Shapes::idx($s, 'd'));
// This is legal, because if `d` is present,
// then it's supportdyn<C>. If it's absent,
// then it's D which is SDT.
expectSDC(Shapes::idx($s, 'd', new D()));
expectSDM(Shapes::idx($s, 'e', 5));
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_shape_lambda.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
interface I {
public function bar():void;
}
type S = supportdyn<shape('a' => supportdyn<(function(I):void)>)>;
function foo():S {
return shape('a' => $x ==> $x->bar());
}
function foo2():supportdyn<(function(I):void)> {
return $x ==> $x->bar();
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_sub_like.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
function expectTrav<T>(~Traversable<T> $_):void { }
function pass(supportdyn<Traversable<mixed>> $x):void {
expectTrav($x);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_sub_like_2.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
class Foo<+T> { }
<<__SupportDynamicType>>
class C { }
function expectLike(~Foo<C> $_):void { }
function gotSD(supportdyn<~Foo<C>> $x):void {
expectLike($x);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_tyvar.good.php | <?hh
function make<T>(supportdyn<T> $x):Vector<supportdyn<T>> {
return Vector{$x};
}
<<__SupportDynamicType>>
class C {
public function foo(): void {}
}
function testit(bool $b):void {
$x = make(null);
// Because we have an invariant type variable, we end up with supportdyn<#0>
$y = $x[0];
if ($b) $y = new C();
$y?->foo();
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/supportdyn_variance.good.php | <?hh
function my_reduce<Tv, Ta>(
Traversable<Tv> $traversable,
supportdyn<(function(Ta, Tv): ~Ta)> $accumulator,
Ta $initial,
): Ta {
return $initial;
}
function f(
vec<int> $components,
int $quantity,
): ~vec<int> {
list($_, $current) = my_reduce(
$components,
($accumulator, $component) ==> {
list($counter, $current) = $accumulator;
$current[] = $component;
return tuple($counter, $current);
},
tuple(0, vec[]),
);
return $current;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/T66877858_good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class Ref<T> {
public function __construct(private T $x) {}
public function get() : T {
return $this->x;
}
public function set(T $x): void {
$this->x = $x;
}
}
function gen_string_dyn() : dynamic {
return "hello";
}
function expect_int(int $x) : void {}
<<__EntryPoint>>
function main() : void {
$r = new Ref(42); // (1.)
$r->set(gen_string_dyn()); // (2.)
expect_int($r->get());
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/test_coerce.good.php | <?hh
function expectDynamic(dynamic $d): void {}
function returnDynamic(): dynamic {
expectDynamic(1);
return 1;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/this_1.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class C<T> {}
<<__SupportDynamicType>>
class D {
public function bar(C<int> $x) : int { return 1; }
public function foo(C<int> $x) : int { return $this->bar($x); }
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/this_2.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class C<T> {}
class E {}
<<__SupportDynamicType>>
class D {
public function bar(E $x) : int { return 1; }
public function foo(C<int> $x) : int { return $this->bar(new E()); }
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/throw.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class C extends Exception { }
<<__SupportDynamicType>>
function test(bool $b, vec<~C> $c, dynamic $d):void {
$x = $c[0];
if ($b) throw $x;
else throw $d;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/toomany.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
function foo(
HH\FormatString<PlainSprintf> $message,
supportdyn<mixed> ...$args
): void {
}
<<__SupportDynamicType>>
function bar(
int $i,
vec<string> $vs,
string $s,
): void {
foo(
'$vs[0] = %s, $i = %20d, $s = %s',
$vs[0],
$i,
$s,
);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/top_level_1.bad.php | <?hh
class A<T> {}
function foo(A<int> $a) : void {}
<<__SupportDynamicType>>
class C {
public function bar(A<int> $v) : void {
foo($v);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/top_level_1.good.php | <?hh
class A<T> {}
<<__SupportDynamicType>>
function foo(A<int> $a) : void {}
<<__SupportDynamicType>>
class C {
public function bar(A<int> $v) : void {
foo($v);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/trait_1.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class Box<T> {}
<<__SupportDynamicType>>
class C {
use T;
}
trait T {
public function bar(Box<int> $x) : Box<int> {
return $x;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/trait_1.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
// A trait that implements dynamic can be used both by classes that do
// and that do not implement dynamic
<<__SupportDynamicType>>
class C {
use T;
}
class D {
use T;
}
<<__SupportDynamicType>>
trait T {} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/trait_2.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
// No checks are performed upon encountering require extends
<<__SupportDynamicType>>
class C {}
class D {}
<<__SupportDynamicType>>
trait T1 {
require extends C;
}
<<__SupportDynamicType>>
trait T2 {
require extends D;
}
trait T3 {
require extends C;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/trait_3.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
// A trait that does not implement dynamic cannot be used by a class that
// implements dynamic
<<__SupportDynamicType>>
class C {
use T;
}
trait T {} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/trait_4.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class Box<T> {}
<<__SupportDynamicType>>
class C {
use T;
}
trait T {
public function foo(int $x) : int {
return $x;
}
<<__SupportDynamicType>>
public function bar(Box<int> $x) : Box<int> {
return $x;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/trait_req_01.good.php | <?hh
// This is accepted. Any class that uses T must be SDT because it
// must implement I, and SDT classes can use non-SDT traits assuming
// all trait elements are themselves SDT.
<<__SupportDynamicType>>
interface I {}
trait T {
require implements I;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/trait_req_02.good.php | <?hh
// fine, as long as all members of T are SDT (following the usual SDT
// trait use rules)
<<file: __EnableUnstableFeatures('require_class') >>
trait T {
require class C;
}
<<__SupportDynamicType>>
final class C {
use T;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/trait_req_03.good.php | <?hh
// fine, provided that all members of C are SDT
<<__SupportDynamicType>>
trait T {
require extends C;
}
class C {
}
<<__SupportDynamicType>>
class D extends C {
use T;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/typeconst_access.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
abstract class HasteJSDep {
abstract const type TIndex as int;
}
<<__SupportDynamicType>>
abstract final class SpinHelper {
public static function getCompDepData<TDep as HasteJSDep, TIndex>(
TDep $dep
): int where TIndex = TDep::TIndex {
$x = self::decode($dep);
return $x[0];
}
private static function decode<TDep as HasteJSDep, TIndex>(
TDep $dep,
): vec<TIndex> where TIndex = TDep::TIndex {
return vec[];
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/typestructure_openshape.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
class C {
const type TC = supportdyn<shape(...)>;
}
<<__SupportDynamicType>>
function expectShape(supportdyn<shape(...)> $s): void { }
<<__SupportDynamicType>>
function getCN():~classname<C> {
throw new Exception("A");
}
<<__SupportDynamicType>>
function test():void {
$cn = getCN();
$s = type_structure($cn, 'TC')['fields'];
expectShape($s);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/type_structure_open_shape_bound.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
function shapeToDict(supportdyn<shape(...)> $shape): ~dict<arraykey, supportdyn<mixed>> {
return dict[];
}
<<__SupportDynamicType>>
abstract class C {
abstract const type TOutput as supportdyn<shape(...)>;
final public static function getOutputFields(): ~dict<arraykey,supportdyn<mixed>> {
$x = type_structure(static::class, 'TOutput')['fields'];
$y = shapeToDict($x);
return $y;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/tyvar_like_app.good.php | <?hh
<<__SupportDynamicType>>
function f(int $i) : void {
}
function likify<T>(T $t) : ~T { return $t; }
function g(dynamic $d) : void {
$v = Vector{};
$v[0] = likify(1);
f($v[0]);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/union_fun.bad.php | <?hh
function test(bool $b): void {
$c = $b ? Vector<int>{} : Set<int> {};
$f = async function ($_): Awaitable<int> { return 42; };
$c->map<int>($f);
$c->map<int>(async function ($_) : Awaitable<int> { return 42; });
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/upcast.bad.php | <?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
function f(mixed $x) : void {
$x upcast dynamic;
}
<<__SupportDynamicType>>
class MyVector<T as supportdyn<mixed>> {}
function h(MyVector<int> $x) : void {
$x upcast MyVector<dynamic>;
$x upcast dynamic;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/upcast.good.php | <?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
function f(int $x) : void {
$y = $x upcast dynamic;
hh_expect_equivalent<dynamic>($y);
}
function g<T as int>(T $x) : void {
$y = $x upcast dynamic;
hh_expect_equivalent<dynamic>($y);
}
function h(vec<int> $x) : void {
$y = $x upcast vec<dynamic>;
hh_expect_equivalent<vec<dynamic>>($y);
$z = $x upcast dynamic;
hh_expect_equivalent<dynamic>($z);
}
function k() : void {
$z = 1 upcast dynamic;
hh_expect_equivalent<dynamic>($z);
}
function j<T as int>(T $x) : void {
$z = ($x + 1) upcast dynamic;
hh_expect_equivalent<dynamic>($z);
}
class C {
public dynamic $d = 3 upcast dynamic;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/variadic_argument_1.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
function f_tuple((int, int) $t) : void {}
<<__SupportDynamicType>>
class C {
public function foo((int, int) ...$x) : void {
f_tuple($x[0]);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/variadic_argument_1.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
class C {
public function foo(int ...$x) : int {
return $x[0];
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/variadic_like.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
function foo(
vec<arraykey> $parts,
): string {
return "A";
}
function bar(arraykey ...$args): string {
return foo(vec($args));
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/variadic_param_callee.good.php | <?hh
<<__SupportDynamicType>>
function f(vec<int> $is): void {
g(...$is);
}
<<__SupportDynamicType>>
function g(int ...$cs): void {} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/varray_explicit.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
function getVarray():~varray<int> {
return vec[];
}
function ret():varray<~int> {
return vec[2];
}
<<__NoAutoDynamic>>
function expectInt(int $_):void { }
function test1(dynamic $d, int $i):void {
$li = getVarray()[0];
$a = varray<int>[$i];
hh_expect_equivalent<varray<int>>($a);
$b = varray<int>[$i, $li];
hh_expect_equivalent<varray<~int>>($b);
$c = varray<int>[$i, $d];
hh_expect_equivalent<varray<~int>>($c);
$d = varray<arraykey>[$i, $li];
hh_expect_equivalent<varray<~arraykey>>($d);
$e = varray<~int>[$i];
hh_expect_equivalent<varray<~int>>($e);
$f = varray<varray<int>>[varray[2,3]];
expectInt($f[0][1]);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/varray_index.good.php | <?hh
function test_dyn_index(dynamic $d, varray<int> $v1) : void {
$a = $v1[$d];
hh_expect_equivalent<int>($a);
$v1[$d] = 1;
$v1[$d] = "s";
$v1[$d] = $d;
}
class C {
public function __construct(private varray<int> $v1) {}
public function f(dynamic $d): void {
$a = $this->v1[$d];
hh_expect_equivalent<int>($a);
$this->v1[$d] = 1;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/vec.good.php | <?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
function dyn(): dynamic { return "4" upcast dynamic; }
function my_vec<T>(T $a, T $b) : vec<T> {
return vec[$a, $b];
}
function test1(): vec<dynamic> {
return vec[1 upcast dynamic, dyn()];
}
function test2(): vec<dynamic> {
return my_vec(1 upcast dynamic, dyn());
}
function test3():void {
vec[5] upcast vec<dynamic>;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/vector_index.bad.php | <?hh
function test_dyn_idx(
dynamic $d,
Vector<int> $v2,
) : void {
$v2[$d] = "s";
$v2[$d] = $d;
}
class C {
public function __construct(private Vector<int> $v2) {}
public function f(dynamic $d): void {
$this->v2[$d] = "s";
$this->v2[$d] = $d;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/vector_index.good.php | <?hh
function test_dyn_index(dynamic $d, Vector<int> $v2) : void {
$a = $v2[$d];
hh_expect_equivalent<~int>($a);
$v2[$d] = 1;
}
class C {
public function __construct(private Vector<int> $v2) {}
public function f(dynamic $d): void {
$a = $this->v2[$d];
hh_expect_equivalent<~int>($a);
$this->v2[$d] = 1;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/vec_expected.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
enum E : int {
A = 1;
B = 2;
}
class CL {
const vec<vec<E>>
CONST = vec[
vec[
E::A,
E::B,
],
];
}
class CL2 {
const vec<vec<int>>
CONST = vec[
vec[
2,
3,
],
];
}
function expectVecVec(vec<vec<int>> $_):void { }
function test1():void {
expectVecVec(vec<vec<int>>[vec[2,3]]);
// Generates vec<int>[2:int,3:int]:vec<int>
$a = vec<int>[2,3];
hh_expect_equivalent<vec<int>>($a);
// Generates vec[2:int,3:int]:vec<int>
$b = vec[2,3];
hh_expect_equivalent<vec<int>>($b);
// Generates vec<vec<int>>[vec[2:int,3:int]:vec<~int>]:vec<vec<~int>>
$c = vec<vec<int>>[vec[2,3]];
hh_expect_equivalent<vec<vec<int>>>($c);
// Generates vec[vec[2:int,3:int]:vec<int>]:vec<vec<int>>
$d = vec[vec[2,3]];
hh_expect_equivalent<vec<vec<int>>>($d);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/vec_explicit.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
function getVec():~vec<int> {
return vec[];
}
function ret():vec<~int> {
return vec[2];
}
<<__NoAutoDynamic>>
function expectInt(int $_):void { }
function test1(dynamic $d, int $i):void {
$li = getVec()[0];
$a = vec<int>[$i];
hh_expect_equivalent<vec<int>>($a);
$b = vec<int>[$i, $li];
hh_expect_equivalent<vec<~int>>($b);
$c = vec<int>[$i, $d];
hh_expect_equivalent<vec<~int>>($c);
$d = vec<arraykey>[$i, $li];
hh_expect_equivalent<vec<~arraykey>>($d);
$e = vec<~int>[$i];
hh_expect_equivalent<vec<~int>>($e);
$f = vec<vec<int>>[vec[2,3]];
expectInt($f[0][1]);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/vec_index.bad.php | <?hh
class C {
public function __construct(private vec<int> $v1) {}
public function f(dynamic $d): void {
$this->v1[$d] = "s";
$this->v1[$d] = $d;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/vec_index.good.php | <?hh
function test_dyn_index(dynamic $d, vec<int> $v1) : void {
$a = $v1[$d];
hh_expect_equivalent<int>($a);
$v1[$d] = 1;
$v1[$d] = "s";
$v1[$d] = $d;
}
class C {
public function __construct(private vec<int> $v1) {}
public function f(dynamic $d): void {
$a = $this->v1[$d];
hh_expect_equivalent<int>($a);
$this->v1[$d] = 1;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/vec_or_dict_await.good.php | <?hh
async function gena<Tk as arraykey, Tv >(
KeyedTraversable<Tk, Awaitable<Tv>> $awaitables,
): Awaitable<dict<Tk, Tv>> {
return dict[];
}
function my_map<Tk as arraykey, Tv1 , Tv2 >(
KeyedTraversable<Tk, Tv1> $traversable,
(function(Tv1): Tv2) $value_func,
): dict<Tk, Tv2>
{ return dict []; }
async function f(mixed $m) : Awaitable<~int> { return 0; }
async function test(
dict<arraykey, mixed> $app_uids,
): Awaitable<~vec_or_dict<int>> {
$a = my_map($app_uids, f<>);
$user_ids = await gena($a);
return $user_ids;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/xhp_attribute.good.php | <?hh // strict
<<__SupportDynamicType>>
interface ILegacyEnum<-TIn as supportdyn<mixed> , TOut as supportdyn<mixed> as TIn> { };
<<__SupportDynamicType>>
abstract class Enum implements ILegacyEnum<this::TInner, this::TInner> {
abstract const type TInner as arraykey;
}
<<__SupportDynamicType>>
final class F extends Enum {
const type TInner = string;
const
A = 'a';
}
<<__SupportDynamicType>>
abstract class XHPTest {
public function __construct(
public ~darray<string,supportdyn<mixed>> $x, // Attributes
public ~varray<supportdyn<mixed>> $y, // Children
public string $z, // Filename
public int $s, // Line number
) {}
}
<<__SupportDynamicType>>
class :foo extends XHPTest {
attribute ~F bar @required;
}
<<__SupportDynamicType>>
function testit(): void {
<foo bar={F::A}/>;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/xhp_enum_attr_like.good.php | <?hh
class :x {
attribute ~enum {'hello'} e;
public function __construct(
dict<string, supportdyn<mixed>> $attributes,
vec<supportdyn<mixed>> $children,
private string $file,
private int $line,
) {}
}
<<__SupportDynamicType>>
function f(): ~string {
return 'hello';
}
function test(): void {
<x e={f()}/>;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/xhp_spread.good.php | <?hh // strict
<<__SupportDynamicType>>
abstract class XHPTest {
public function __construct(
public ~darray<string,supportdyn<mixed>> $a, // Attributes
public ~varray<supportdyn<mixed>> $b, // Children
public string $c, // Filename
public int $d, // Line number
) { }
public function getAttribute(
string $_attribute,
mixed $_default = null
): mixed {
return null;
}
}
<<__SupportDynamicType>>
class :other extends XHPTest { }
<<__SupportDynamicType>>
class :baz extends XHPTest {
attribute ~:other x;
}
<<__SupportDynamicType>>
class :bar {
// Import all attributes from :baz
attribute :baz;
}
<<__SupportDynamicType>>
class :foo extends XHPTest {
// Import all attributes from :bar
attribute :bar;
}
<<__SupportDynamicType>>
function test1(:foo $obj): :baz {
$x = $obj->:x;
$x as nonnull;
return <baz x={<other {...$x}/>}/>;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/xhp_spread_required.good.php | <?hh // strict
abstract class XHPTest {
public function __construct(
public darray<string,mixed> $a, // Attributes
public varray<mixed> $b, // Children
public string $c, // Filename
public int $d, // Line number
) { }
}
class :x extends XHPTest { attribute int a @required; }
class :z extends XHPTest { attribute int a @required; attribute int b; }
function bar(bool $b, dynamic $d): void {
// Effectively construct a like-type
if ($b) {
$a = <x a={1}/>;
} else {
$a = $d;
}
$c = <z {...$a} />;
} |
hhvm/hphp/hack/test/sound_dynamic/typing/completeness_bugs/dune | (rule
(alias sound_dynamic_typing_completeness_bugs_bad)
(deps
%{exe:../../../../src/hh_single_type_check.exe}
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/review.sh
(glob_files %{project_root}/hack/test/sound_dynamic/typing/completeness_bugs/HH_FLAGS)
(glob_files %{project_root}/hack/test/sound_dynamic/typing/completeness_bugs/*.bad.php)
(glob_files %{project_root}/hack/test/sound_dynamic/typing/completeness_bugs/*.bad.php.exp)
(glob_files
%{project_root}/hack/test/sound_dynamic/typing/completeness_bugs/*.bad.php.legacy_decl.exp))
(action
(run
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/sound_dynamic/typing/completeness_bugs
--program
%{exe:../../../../src/hh_single_type_check.exe}
--batch
--in-extension
.bad.php
--out-extension
.legacy_decl.out
--expect-extension
.legacy_decl.exp
--fallback-expect-extension
.exp
--flags
--enable-sound-dynamic-type
--out-extension
.legacy_decl.out
--error-format
plain)))
(alias
(name runtest)
(deps
(alias sound_dynamic_typing_completeness_bugs_bad))) |
|
hhvm/hphp/hack/test/sound_dynamic/typing/completeness_bugs/HH_FLAGS | --allowed-fixme-codes-strict 1002,2049,2053,2063,2121,4009,4029,4030,4051,4054,4055,4064,4090,4101,4102,4110,4123,4128,4323,4338,4341,9999,4107
--allowed-decl-fixme-codes 1002,2049,2053,4030,4054,4101,4338,4341
--enable-sound-dynamic-type --enable-supportdyn-hint --union-intersection-type-hints --like-type-hints |
|
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/completeness_bugs/static_method_1.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class Evil<T> {}
<<__SupportDynamicType>>
class C {
public static function foo(Evil<int> $v) : Evil<int> {
return $v;
}
public function bar(Evil<int> $v) : Evil<int> {
return self::foo($v);
}
} |
hhvm/hphp/hack/test/sound_dynamic/typing/nonad/HH_FLAGS | --enable-sound-dynamic-type --enable-supportdyn-hint --union-intersection-type-hints --like-type-hints |
|
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/nonad/nonad.bad.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__NoAutoDynamic>>
class C {}
<<__NoAutoDynamic>>
function foo():void { }
class D {
<<__NoAutoDynamic>>
public function bar():void { }
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.