language
stringlengths 0
24
| filename
stringlengths 9
214
| code
stringlengths 99
9.93M
|
---|---|---|
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/forward3.php | <?hh
function f(dict<string, mixed> $d): void {
idx($d, 'b');
}
function g(): void {
f(dict['a' => 42]);
}
function h(): void {
f(dict['c' => true]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/recursion.php | <?hh
function f(dict<string, mixed> $d) : void {
$d['a'];
g($d);
}
function g(dict<string, mixed> $d) : void {
$d['b'];
f($d);
}
function main(): void {
f(dict['a' => true, 'b' => 42]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/return1.php | <?hh
// expect return hint: shape('a' => int)
function foo(): dict<string, mixed> {
return bar();
}
function bar(): dict<string, mixed> {
return dict['a' => 3];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/return2.php | <?hh
// expect return hint: shape('a' => int, 'b' => int)
function foo(): dict<string, mixed> {
$d = bar();
$d['b'] = 1;
return $d;
}
function bar(): dict<string, mixed> {
return dict['a' => 1];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/return3.php | <?hh
// expect return hint: `shape('a' => mixed)`
function foo(): dict<string, mixed> {
$d = bar();
$d['a']; // expect `Shapes::idx($d, 'a')`
return $d;
}
function bar(): dict<string, mixed> {
return dict[];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/return4.php | <?hh
// Expect return hint with `a` key
function foo(): dict<string, mixed> {
$d1 = dict['a' => 1];
$d2 = dict_identity($d1);
return $d2;
}
// Expect return hint with `b` key
function bar(): dict<string, mixed> {
$d1 = dict['b' => 1];
$d2 = dict_identity($d1);
return $d2;
}
// expect hints that type-check
function dict_identity(dict<string, mixed> $d): dict<string, mixed> {
return $d;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/trait_const_1_wip.php | <?hh
trait TheTrait {
// T136213776: expect ?b key in shape type
const dict<string, mixed> DICT = dict[];
}
class TheClass {
use TheTrait;
}
function main(): void {
TheClass::DICT['b'];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/trait_const_2_wip.php | <?hh
class TheParent {
// T136213776: expect ?'b' key
const dict<string, string> DICT = dict["a" => "2"];
}
trait Childish {
require extends TheParent;
public static function foo(): void {
parent::DICT['b'];
}
}
class Child extends TheParent {
use Childish;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/argument_as_dynamic.php | <?hh
function g(dict<string, mixed> $d): void {}
function f(): void {
$d = dict['a' => 42];
$e = dict['b' => true];
g($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/awaitable.php | <?hh
async function f(): Awaitable<dict<string, mixed>> {
// Shouldn't produce a result because it escapes local definition
return dict[];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/class.php | <?hh
class C {
public function f(bool $b): void {
$d = dict['a' => 42, 'b' => true];
if ($b) {
$d['c'] = 'hi';
}
$d['f'] = 24.0;
}
public function g(bool $b): void {
$d = dict['a' => 42, 'b' => true];
if ($b) {
$d['c'] = 'hi';
}
$d['f'] = 24.0;
}
} |
hhvm/hphp/hack/test/shape_analysis/tast_check/dune | (rule
(alias shape_analysis)
(deps
%{exe:../../../src/hh_single_type_check.exe}
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/review.sh
%{project_root}/hack/test/shape_analysis/hhi/shape_analysis_test.hhi
%{project_root}/hack/test/shape_analysis/tast_check/HH_FLAGS
(glob_files %{project_root}/hack/test/shape_analysis/tast_check/*.php)
(glob_files %{project_root}/hack/test/shape_analysis/tast_check/*.php.exp))
(action
(run
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/shape_analysis/tast_check
--program
%{exe:../../../src/hh_single_type_check.exe}
--in-extension
.php
--flags
--union-intersection-type-hints
--shape-analysis simplify:local
--error-format
plain)))
(alias
(name runtest)
(deps
(alias shape_analysis))) |
|
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/dynamic.php | <?hh
function f(): void {
$key = 'key';
dict[$key => 42]; // No shape-like dicts are reported here
dict['key' => 42]; // A shape-like dict is reported here
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/function.php | <?hh
function f(bool $b): void {
$d = dict['a' => 42, 'b' => true];
if ($b) {
$d['c'] = 'hi';
}
$d['f'] = 24.0;
$e = dict[];
$f = dict['a' => true];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/incomplete.php | <?hh
class :div {
public function __construct(
dict<string, mixed> $attributes,
vec_or_dict<mixed> $children,
string $file,
int $line
): void {}
}
class C {
public function f(C $c): void {
// XHP is not yet supported
<div />;
}
public function g(): void {
dict['a' => 42, 'b' => true];
}
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/inout_arg.php | <?hh
class C {
public function m(inout dict<string,int> $i): void {}
}
function main1(C $c): void {
$d = dict['a' => 0];
$c->m(inout $d);
}
function f(inout dict<string,int> $i): void {}
function main2(): void {
$d = dict['a' => 0];
f(inout $d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/liberal_collection_access.php | <?hh
function takes_int(int $_): void {}
function takes_dict(dict<string, mixed> $_): void {}
function takes_tuple((int, dict<string, mixed>) $_): void {}
// Keep the result because only a non-collection flows outside
function dont_invalidate(): void {
$d = dict['a' => 42];
takes_int($d['a']);
$t = tuple(42, dict['a' => 42]);
takes_int($t[0]);
}
// Invalidate the result because dict flows outside
function invalidate(): void {
$d = dict['a' => dict[]];
takes_dict($d['a']);
$t = tuple(42, dict['a' => 42]);
takes_dict($t[1]);
$t = tuple(42, tuple(42, dict['a' => 42]));
takes_tuple($t[1]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/liberal_inout.php | <?hh
function f(mixed $_, inout mixed $_): void {}
function test(): void {
$d1 = dict[]; // Not invalidated
$d2 = dict[]; // Not invalidated
f($d1, inout $d2);
$v1 = vec[dict[]]; // Not invalidated
$v2 = vec[dict[]]; // Invalidated because we don't know what flows back into $d2
$v1[] = $d1;
$v2[] = $d2;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/liberal_inter_procedural.php | <?hh
function f(mixed $_, dict<string, mixed> $_, mixed $_): void {}
class C {
public function m(mixed $_, dict<string, mixed> $_, mixed $_): void {}
public static function s(mixed $_, dict<string, mixed> $_, mixed $_): void {}
}
class D {
public function m(mixed $_, dict<string, mixed> $_, mixed $_): void {}
}
function test_function(): void {
$d1 = dict[]; // Not invalidated
$d2 = dict[]; // Invalidated
$d3 = dict[]; // Not invalidated
f($d1, $d2, $d3);
}
function test_method(C $c): void {
$d1 = dict[]; // Not invalidated
$d2 = dict[]; // Invalidated
$d3 = dict[]; // Not invalidated
$c->m($d1, $d2, $d3);
}
function test_class_method(): void {
$d1 = dict[]; // Not invalidated
$d2 = dict[]; // Invalidated
$d3 = dict[]; // Not invalidated
C::s($d1, $d2, $d3);
}
function test_union(C $c, D $d): void {
$d1 = dict[]; // Not invalidated
$d2 = dict[]; // Invalidated
$d3 = dict[]; // Not invalidated
$o = 1 === 2 ? $c : $d;
$o->m($d1, $d2, $d3);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/method_call.php | <?hh
class C {
public function f(string $s, dict<string,mixed> $d, int $i): void {}
}
function main(C $c): void {
$d1 = dict['a' => 42];
$d2 = dict['w' => 'hi'];
$c->f('apple', $d1, 42);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/nested.php | <?hh
function f(): dict<string, mixed> {
// We should get no results for because both dictinaries escape their local
// definition.
return dict['a' => dict['b' => 42]];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/nested_escape.php | <?hh
function escapes_via_return(): vec<mixed> {
return vec[dict[]];
}
function influenced_via_param(vec<dict<string, mixed>> $arg): void {
$v = vec[dict[]];
$v[] = $arg[0];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/new.php | <?hh
class C {
public function __construct(dict<string, mixed> $_): void {}
}
function f(): void {
$d1 = dict[]; // This result is reported
$d2 = dict[]; // This result is invalidated
new C($d2);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/prop_read.php | <?hh
class C {
public dict<string, mixed> $instance_prop = dict[];
public static dict<string, mixed> $class_prop = dict[];
}
function instance_write(C $c): void {
vec[dict[], $c->instance_prop];
}
function class_write(): void {
vec[dict[], C::$class_prop];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/prop_write.php | <?hh
class C {
public dict<string, mixed> $instance_prop = dict[];
public static dict<string, mixed> $class_prop = dict[];
}
function instance_write(C $c): void {
$d = dict[];
$c->instance_prop = $d;
}
function class_write(): void {
$d = dict[];
C::$class_prop = $d;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/prop_write_liberal.php | <?hh
class C {
public mixed $instance_prop = dict[];
public static mixed $class_prop = dict[];
}
function instance_write(C $c): void {
$d = dict[];
// Do not invalidate the dict above because flows into mixed
$c->instance_prop = $d;
}
function class_write(): void {
$d = dict[];
// Do not invalidate the dict above because flows into mixed
C::$class_prop = $d;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/return_as_dynamic.php | <?hh
function f(): dict<string, mixed> {
$d = dict['a' => 42];
$e = dict['b' => true];
return $d;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/tast_check/unpack.php | <?hh
class C {
public function splat_m(num ...$n): void {}
}
function main1(C $c): void {
$c->splat_m(...dict["a" => 42, "b" => 42.0]);
}
function splat_f(num ...$n): void {}
function main2(): void {
splat_f(...dict["a" => 42, "b" => 42.0]);
} |
hhvm/hphp/hack/test/sound_dynamic/decl/dune | (rule
(alias sound_dynamic_typing_decl)
(deps
%{exe:../../../src/hh_single_decl.exe}
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/review.sh
(glob_files %{project_root}/hack/test/sound_dynamic/decl/HH_FLAGS)
(glob_files %{project_root}/hack/test/sound_dynamic/decl/*.php)
(glob_files %{project_root}/hack/test/sound_dynamic/typing/*.exp))
(action
(run
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/sound_dynamic/decl
--program
%{exe:../../../src/hh_single_decl.exe}
--flags
--decl-parse)))
(rule
(alias sound_dynamic_typing_decl_typing)
(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/decl/HH_FLAGS)
(glob_files %{project_root}/hack/test/sound_dynamic/decl/*.php)
(glob_files %{project_root}/hack/test/sound_dynamic/decl/*.exp))
(action
(run
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/sound_dynamic/decl
--program
%{exe:../../../src/hh_single_type_check.exe}
--out-extension
.typecheck.out
--expect-extension
.typecheck.exp
--batch
--flags
--error-format
plain
--enable-higher-kinded-types
--enable-supportdyn-hint)))
(alias
(name runtest)
(deps
(alias sound_dynamic_typing_decl)
(alias sound_dynamic_typing_decl_typing))) |
|
PHP | hhvm/hphp/hack/test/sound_dynamic/skipcheck/skipcheck.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
class Box<T> {
public function __construct(private T $item) { }
public function set(T $x):void { $this->item = $x; }
public function get(): T { return $this->item; }
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/arith.good.php | <?hh
enum E : int as int {
C1 = 1;
}
function f(num $n, int $i, float $f, E $e, dynamic $d) : void {
$x1 = $n + $d;
$x2 = $i + $d;
$x3 = $f + $d;
$x4 = $e + $d;
$x5 = $d + $d;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/as.bad.php | <?hh
class C<T> {}
<<__SupportDynamicType>> class D<T> extends C<T> {}
function expect_d_int(D<int> $d) : void {}
function test(~C<int> $x) : void {
if ($x is D<_>) {
expect_d_int($x);
}
$x as D<_>;
expect_d_int($x);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/as2.bad.php | <?hh
class Box<<<__RequireDynamic>> T> {
public T $p;
public function __construct(T $x) {
$this->p = $x;
}
public function get() : T {
return $this->p;
}
public function set(T $x) : void {
$this->p = $x;
}
}
function f(Box<int> $x) : void {
$y = $x as dynamic;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/as3.good.php | <?hh
class C<T> {}
<<__SupportDynamicType>> class D<T> extends C<T> {}
function expect_like_d_int(~D<int> $d) : void {}
function test(~C<int> $x) : void {
if ($x is D<_>) {
expect_like_d_int($x);
}
$x as D<_>;
expect_like_d_int($x);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/as_nonnull_like_call.good.php | <?hh
<<__SupportDynamicType>>
class C {}
<<__SupportDynamicType>>
function getC(): ~?C {
return new C();
}
<<__SupportDynamicType>>
function foo(C $_): void {}
<<__SupportDynamicType>>
function bar(): void {
$nc = getC();
$nc as nonnull;
foo($nc);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/awaitable.bad.php | <?hh
class Box {
public function __construct(public int $data) {}
}
<<__SupportDynamicType>>
class D {
public async function box(): Awaitable<Box> {
return new Box(42);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/awaitable.good.php | <?hh
<<__SupportDynamicType>>
class Box {
public function __construct(public int $data) {}
}
<<__SupportDynamicType>>
class D {
public async function foo() : Awaitable<void> {
}
public async function box(): Awaitable<Box> {
return new Box(42);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/bidirectional.bad.php | <?hh
<<__SupportDynamicType>>
function f(): (function (int, shape()): void) {
// during SDT pass when `expected` type is dynamic
return (int $i, $s) ==> {
nosdt_int($i); // $i: (dynamic & int) ; OK
nosdt_shape($s); // $s: dynamic ; error
};
}
function nosdt_int(int $i): void {}
function nosdt_shape(shape() $s): void {} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/bidirectional.good.php | <?hh
class A {
public function c(): void {}
}
<<__SupportDynamicType>>
function f(): ~vec<(function (A): void)> {
return vec[
($f) ==> { $f->c(); }
];
}
<<__SupportDynamicType>>
function g(): ~dict<string, (function (A): void)> {
return dict[
'hi' => ($f) ==> { $f->c(); }
];
}
<<__SupportDynamicType>>
function ff(): ~Traversable<(function (A): void)> {
return vec[
($f) ==> { $f->c(); }
];
}
<<__SupportDynamicType>>
function gg(): ~KeyedTraversable<string, (function (A): void)> {
return dict[
'hi' => ($f) ==> { $f->c(); }
];
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/box.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
class BoxInt {
public function __construct(private int $x) {}
public function set(int $y) : void {$this->x = $y;}
public function get() : int {return $this->x;}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/box_generics.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
class Box<T> {
public function __construct(private T $x) {}
public function set(T $y) : void {$this->x = $y;}
public function get() : T {return $this->x;}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/box_sdt_call.bad.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<file:__EnableUnstableFeatures('upcast_expression')>>
class Box<T> {
public function __construct(private T $x) {}
public function get() : T { return $this->x; }
public function set(T $x) : void { $this->x = $x; }
}
<<__SupportDynamicType>>
class ROBox<T> {
public function __construct(private T $x) {}
public function get() : T { return $this->x; }
}
<<__SupportDynamicType>>
function f(Box<int> $v1, ROBox<int> $v2) : void {
$v1->set($v2->get());
}
<<__EntryPoint>>
function main() : void {
$v1 = new Box<int>(1);
$v2 = new ROBox<string>("abcd") upcast dynamic;
f($v1, $v2);
print $v1->get();
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/call_meth_1.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class A<T> {}
class C {
<<__SupportDynamicType>>
public function expect_A_int(A<int> $a1, A<int> $a2) : void {}
}
// handling of Sound Dynamic Callable methods defined in other classes
// is not complete; this should ideally be accepted, but it is not
<<__SupportDynamicType>>
class Foo {
public function foo(A<int> $a) : void {
(new C())->expect_A_int($a, new A<int>());
}
public function bar(A<int> $a) : void {
(new C())->expect_A_int(new A<int>(), $a);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/call_meth_1.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
class A<<<__RequireDynamic>> T> {}
class C {
<<__SupportDynamicType>>
public function expect_A_int(A<int> $a) : void {}
}
<<__SupportDynamicType>>
class D {
public function expect_A_int(A<int> $a) : void {}
}
<<__SupportDynamicType>>
class Foo {
public function foo(A<int> $a) : void {
(new C())->expect_A_int($a);
(new C())->expect_A_int(new A<int>());
(new D())->expect_A_int($a);
(new D())->expect_A_int(new A<int>());
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/call_through_string.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
class C {
public static function foo():void { }
}
<<__SupportDynamicType>>
interface Get {
public function get():string;
}
<<__SupportDynamicType>>
class D implements Get {
public function get():(~classname<C> & string) {
return C::class;
}
}
<<__SupportDynamicType>>
function test(vec<int> $_):void {
$d = new D();
$c = $d->get();
$c::foo();
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/capability_variable.good.php | <?hh
<<__SupportDynamicType>>
class C<<<__RequireDynamic>> T> {}
<<__SupportDynamicType>>
function f(): void {}
<<__SupportDynamicType>>
function g<T>(C<T> $c): void {
// SDT pass should not error about $#capability
f();
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/check_sdt_meth.bad.php | <?hh
<<__SupportDynamicType>>
class D {
public function f(vec<int> $x) : vec<int> { return $x; } }
<<__SupportDynamicType>>
class C {
public function g(vec<int> $v) : vec<int> {
if ($v is vec<_>) {
return vec[4];
}
else {
// $v : nothing in first check and $v : dynamic & not vec in second
return (new D())->f($v, 4);
}
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/check_sdt_meth.good.php | <?hh
<<__SupportDynamicType>>
class D {
public function f(vec<int> $x) : vec<int> { return $x; } }
<<__SupportDynamicType>>
class C {
public function g(vec<int> $v) : vec<int> {
if ($v is vec<_>) {
return vec[4];
}
else {
// $v : nothing in first check and $v : dynamic & not vec in second
return (new D())->f($v);
}
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/circular_type.good.php | <?hh
interface PredBase<-T , Tcontext > {}
interface Pred<-T , Tcontext >
extends PredBase<T, Tcontext> {
}
interface PredRange<Tv , Tcontext >
extends Pred<Tv, Tcontext> {
}
class C<T1 , T2 > implements PredRange<T1, T2> {}
function and_<Tv, Tcontext >(
Pred<Tv, Tcontext> $predicates,
Pred<Tv, Tcontext> $predicates2,
): Pred<Tv, Tcontext> {
return new C();
}
function greaterThanOrEquals<Tv , Tcontext >(
Tv $value,
): PredRange<Tv, Tcontext> {
return new C();
}
function lessThan< Tv as supportdyn<mixed> , Tcontext >(
Tv $value,
): PredRange<Tv, Tcontext> {
return new C();
}
function f(
int $lower_time,
int $upper_time,
): void
{
$lt =lessThan($upper_time);
$gte =greaterThanOrEquals($lower_time);
$and = and_($lt, $gte);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/closure_captures_like.good.php | <?hh
enum A : int {}
enum B : int {}
enum C : int {}
<<__SupportDynamicType>>
function f(A $a): void {
hh_show($a);
$c1 = (B $b) ==> {
hh_show($a);
hh_show($b);
$c2 = (C $c) ==> {
hh_show($a);
hh_show($b);
hh_show($c);
};
};
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/coalesce_shape_access.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
type TShape = supportdyn<shape(
'a' => supportdyn<shape(
'b' => string,
...
)>,
...
)>;
function test(
~TShape $s,
): ~string {
$y = $s['a'] ?? dict[];
$z = $y['b'];
return $z;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/coerce_to_dyn.bad.php | <?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
class C {}
function test_prim(mixed $m, nonnull $n, C $c) : void {
//hh_log_level('sub', 2);
$c upcast dynamic;
$m upcast dynamic;
$n upcast dynamic;
}
function test_contain((string, C) $t, vec<C> $v, dict<string, C> $di,
darray<arraykey, C> $da,
varray<C> $va)
: void {
$t upcast dynamic;
$v upcast dynamic;
$di upcast dynamic;
$da upcast dynamic;
$va upcast dynamic;
}
function test_shape(shape('x' => int, ?'y' => vec<C>) $s) : void {
$s upcast dynamic;
}
function test_container_context(vec<C> $v,
dict<int, C> $d,
darray<arraykey, C> $da,
varray<C> $va) : void {
$v upcast vec<dynamic>;
$d upcast dict<arraykey, dynamic>;
}
function test_shape_context(shape('x' => int, ?'y' => C) $s) : void {
$s upcast shape('x' => dynamic, ?'y' => dynamic);
}
class V1<<<__RequireDynamic>> T> {};
class V2<<<__RequireDynamic>> +T> {};
function test_class_context(V1<int> $v1, V2<C> $v2) : void {
$v1 upcast V1<dynamic>;
$v2 upcast V2<dynamic>;
}
function test_union(int $i, C $c, bool $b) : void {
if ($b) {
$x = $i;
} else {
$x = $c;
}
$x upcast dynamic;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/coerce_to_dyn.good.php | <?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
class C {
public function m() : void {}
}
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 upcast dynamic;
}
function test_prim(bool $b, int $i, float $f, num $n, string $s, arraykey $ak, resource $r)
: void {
$b upcast dynamic;
$i upcast dynamic;
$f upcast dynamic;
$n upcast dynamic;
$s upcast dynamic;
$r upcast dynamic;
$c = new C() upcast dynamic;
$c->m() upcast dynamic;
null upcast dynamic;
$ak upcast dynamic;
E1::CONST1 upcast dynamic;
E2::CONST2 upcast dynamic;
E3::CONST3 upcast dynamic;
E4::CONST4 upcast dynamic;
}
function test_contain((string, int) $t, vec<int> $v, dict<string, int> $di,
keyset<arraykey> $ks, darray<arraykey, vec<C>> $da,
varray<int> $va, ?int $oi)
: void {
$t upcast dynamic;
$v upcast dynamic;
$di upcast dynamic;
$ks upcast dynamic;
$da upcast dynamic;
$va upcast dynamic;
$oi upcast dynamic;
}
function test_shape(shape('x' => int, ?'y' => vec<C>) $s) : void {
$s upcast dynamic;
}
<<__SupportDynamicType>>
class D<T> {}
<<__SupportDynamicType>>
class E {}
function test_class(C $c, D<int> $di, D<E> $de) : void {
$c upcast dynamic;
$di upcast dynamic;
$de upcast dynamic;
}
function test_container_context(vec<int> $v,
dict<int, C> $d,
?int $o) : void {
$v upcast vec<dynamic>;
$d upcast dict<arraykey, dynamic>;
$o upcast ?dynamic;
}
function test_shape_context(shape('x' => int, ?'y' => vec<C>) $s) : void {
$s upcast shape('x' => dynamic, ?'y' => dynamic);
}
class V2<+T> {};
class V3<-T> {};
function test_class_context(V2<int> $v2, V3<mixed> $v3) : void {
$v2 upcast V2<dynamic>;
$v3 upcast V3<dynamic>;
}
function test_union(int $i, C $c, bool $b) : void {
if ($b) {
$x = $i;
} else {
$x = $c;
}
$x upcast dynamic;
}
function test_inter(int $i, bool $b) : void {
if ($i is E) {
$i upcast dynamic;
}
}
function test_expression_helper() : int {
return 10;
}
function test_expression(int $i) : void {
$x = test_expression_helper() upcast dynamic;
$y = ($i + 1) upcast dynamic;
$z = 1 upcast dynamic;
$m = (1 upcast int) + 1;
$n = 1 + (1 upcast int);
$o = 1 upcast int + 1;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/constructor_like_call.good.php | <?hh
<<__SupportDynamicType>>
class C {
public function __construct(
private string $s,
private int $i,
private string $x,
) {}
}
<<__SupportDynamicType>>
function newC(string $s, int $i, string $x): C {
return new C($s, $i, $x);
}
function getString(): ~string {
return "A";
}
function getInt(): ~int {
return 3;
}
<<__SupportDynamicType>>
function test(): void {
$s = getString();
$i = getInt();
$c = newC($s, $i, "A");
$c = new C($s, $i, "A");
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/darray_explicit.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
function getVec():~vec<int> {
return vec[];
}
function getStrings():~vec<string> {
return vec[];
}
<<__NoAutoDynamic>>
function expectInt(int $_):void { }
function test1(dynamic $dyn, int $i):void {
$li = getVec()[0];
$ls = getStrings()[0];
$a = darray<string,int>['a' => $i];
hh_expect_equivalent<darray<string,int>>($a);
$b = darray<string,int>['a' => $i, 'b' => $li];
hh_expect_equivalent<darray<string,~int>>($b);
$c = darray<string,int>['a' => $i, 'b' => $dyn];
hh_expect_equivalent<darray<string,~int>>($c);
$d = darray<string,arraykey>['a' => $i, 'b' => $li];
hh_expect_equivalent<darray<string,~arraykey>>($d);
$d[$ls] = 5;
hh_expect_equivalent<darray<(~string & arraykey),~arraykey>>($d);
$e = darray<string,int>[$ls => $i];
hh_expect_equivalent<darray<(~string & arraykey),int>>($e);
$f = darray<string, darray<string, int>>['bar' => darray['baz' => 42]];
expectInt($f['a']['b']);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/darray_index.good.php | <?hh
function test_dyn_index(
dynamic $d,
darray<int, int> $dt1,
darray<arraykey, int> $dt2,
) : void {
$a = $dt1[$d];
hh_expect_equivalent<int>($a);
$a = $dt2[$d];
hh_expect_equivalent<int>($a);
$dt1[$d] = 1;
$dt1[$d] = "s";
hh_expect_equivalent<darray<((arraykey&dynamic)|int), (int|string)>>($dt1);
$dt2[$d] = $d;
$dt2[$d] = 1;
$dt2[$d] = "s";
$dt2[$d] = $d;
}
class C<Tk as arraykey> {
public function __construct(
private darray<Tk, int> $dt1,
private darray<arraykey, int> $dt2,
private darray<int, int> $dt3,
) {}
public function f(dynamic $d): void {
$a = $this->dt1[$d];
hh_expect_equivalent<int>($a);
$a = $this->dt2[$d];
hh_expect_equivalent<int>($a);
$a = $this->dt3[$d];
hh_expect_equivalent<int>($a);
$this->dt2[$d] = 1;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/default_param.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
namespace DefParam;
function getVecInt()[]:vec<int> {
return vec[5,6];
}
<<__SupportDynamicType>>
class C {
public static ~vec<int> $lvi = vec[3,4];
// Enforced, so we permit default expression to have type ~int but then the parameter should have type int in the body
public static function foo(int $arg = self::$lvi[0]):void { hh_expect<int>($arg); }
// Not enforced, but we permit default expression to have type ~vec<int> and this is the type that it will have in the body
public static function bar(vec<int> $arg = self::$lvi):void { hh_expect_equivalent<~vec<int>>($arg); }
// Not enforced, but we preserve the type vec<int> of the default expression through to the body
public static function boo(vec<int> $arg = getVecInt()):void { expectVecInt($arg); }
}
<<__SupportDynamicType>>
function expectVecInt(vec<int> $_):void { } |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/dict_create.good.php | <?hh
function test_create_dyn_idx(dynamic $d) : dict<(~int & arraykey), int> {
dict<arraykey, int>[$d => 1, 1 => 1];
$x = dict[$d => 1, 1 => 1];
hh_expect_equivalent<dict<(~int & arraykey), int>>($x);
return dict[$d => 1, 1 => 1];
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/dict_dyn_key.good.php | <?hh
function f(dynamic $d) : void {
$dict = dict[];
$dict[$d] = 1;
hh_expect_equivalent<dict<(arraykey&dynamic), int>>($dict);
$dict[1];
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/dict_enumkey.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
enum E: int as int {
A = 3;
}
<<__SupportDynamicType>>
function getDict():dict<E,string> {
return dict[];
}
<<__SupportDynamicType>>
interface I {
public function getKey():int;
}
<<__SupportDynamicType>>
class C implements I {
public function getKey():(~E & int) {
return E::A;
}
}
<<__SupportDynamicType>>
function testit():void {
$c = new C();
$y = getDict();
$z = $c->getKey();
$x = $y[$z];
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/dict_explicit.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
function getVec():~vec<int> {
return vec[];
}
function getStrings():~vec<string> {
return vec[];
}
<<__NoAutoDynamic>>
function expectInt(int $_):void { }
function test1(dynamic $dyn, int $i):void {
$li = getVec()[0];
$ls = getStrings()[0];
$a = dict<string,int>['a' => $i];
hh_expect_equivalent<dict<string,int>>($a);
$b = dict<string,int>['a' => $i, 'b' => $li];
hh_expect_equivalent<dict<string,~int>>($b);
$c = dict<string,int>['a' => $i, 'b' => $dyn];
hh_expect_equivalent<dict<string,~int>>($c);
$d = dict<string,arraykey>['a' => $i, 'b' => $li];
hh_expect_equivalent<dict<string,~arraykey>>($d);
$d[$ls] = 5;
hh_expect_equivalent<dict<(~string & arraykey),~arraykey>>($d);
$e = dict<string,int>[$ls => $i];
hh_expect_equivalent<dict<(~string & arraykey),int>>($e);
$f = dict<string, dict<string, int>>['bar' => dict['baz' => 42]];
expectInt($f['a']['b']);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/dict_index.bad.php | <?hh
class C<Tk as arraykey> {
public function __construct(
private dict<Tk, int> $dt1,
private dict<arraykey, int> $dt2,
private dict<int, int> $dt3,
) {}
public function f(dynamic $d): void {
$this->dt1[$d] = 1;
$this->dt3[$d] = 1;
$this->dt1[$d] = "s";
$this->dt2[$d] = "s";
$this->dt3[$d] = "s";
$this->dt1[$d] = $d;
$this->dt2[$d] = $d;
$this->dt3[$d] = $d;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/dict_index.good.php | <?hh
function test_dyn_index(
dynamic $d,
dict<int, int> $dt1,
dict<arraykey, int> $dt2,
) : void {
$a = $dt1[$d];
hh_expect_equivalent<int>($a);
$a = $dt2[$d];
hh_expect_equivalent<int>($a);
$dt1[$d] = 1;
$dt1[$d] = "s";
hh_expect_equivalent<dict<((arraykey&dynamic)|int), (int|string)>>($dt1);
$dt2[$d] = $d;
$dt2[$d] = 1;
$dt2[$d] = "s";
$dt2[$d] = $d;
}
class C<Tk as arraykey> {
public function __construct(
private dict<Tk, int> $dt1,
private dict<arraykey, int> $dt2,
private dict<int, int> $dt3,
) {}
public function f(dynamic $d): void {
$a = $this->dt1[$d];
hh_expect_equivalent<int>($a);
$a = $this->dt2[$d];
hh_expect_equivalent<int>($a);
$a = $this->dt3[$d];
hh_expect_equivalent<int>($a);
$this->dt2[$d] = 1;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/dict_keyset_index.good.php | <?hh
function test(dynamic $y):void {
$y as nonnull;
$x = keyset[];
$d = dict[];
$x[] = $y;
$d[$y] = 3;
hh_expect_equivalent<keyset<(arraykey & dynamic)>>($x);
hh_expect_equivalent<dict<(arraykey & dynamic), int>>($d);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/ditch_dynamic_method.good.php | <?hh
class NotSDT {}
<<__SupportDynamicType>>
class SDT {}
function f(): void {
$x = "dyn_func";
/* HH_FIXME[2121] */
$y_fatal = NotSDT::$x(); // DITCH will make this fatal
hh_expect_equivalent<dynamic>($y_fatal); // so it's safe to say this is dynamic (nothing)
/* HH_FIXME[2121] */
$y_ok = SDT::$x(); // SDT class guarantees the "dyn_func" method will return a value that supports dynamic
hh_expect_equivalent<dynamic>($y_ok);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/div.good.php | <?hh
<<__SupportDynamicType>>
function div_int_int(int $x, int $y) : num {
return $x / $y;
}
<<__SupportDynamicType>>
function div_float_float(float $x, float $y) : float {
return $x / $y;
}
<<__SupportDynamicType>>
function div_num_num(num $x, num $y) : num {
return $x / $y;
}
<<__SupportDynamicType>>
function div_nothing_nothing(nothing $x, nothing $y) : nothing {
return $x / $y;
}
<<__SupportDynamicType>>
function div_num_nothing(num $x, nothing $y) : nothing {
return $x / $y;
}
<<__SupportDynamicType>>
function div_num_int(num $x, int $y) : num {
return $x / $y;
}
<<__SupportDynamicType>>
function div_float_int(float $x, int $y) : float {
return $x / $y;
}
<<__SupportDynamicType>>
function div_float_num(float $x, num $y) : float {
return $x / $y;
}
function test(dynamic $d, int $i, float $f, num $n, vec<~int> $vi, vec<~float> $vf, vec<~num> $vn) : void {
hh_expect_equivalent<num>($i / $i);
hh_expect_equivalent<float>($f / $f);
hh_expect_equivalent<num>($n / $n);
hh_expect_equivalent<num>($n / $i);
hh_expect_equivalent<float>($f / $i);
hh_expect_equivalent<float>($f / $n);
hh_expect_equivalent<~num>($vi[0] / $i);
hh_expect_equivalent<~float>($vf[0] / $f);
hh_expect_equivalent<~num>($vn[0] / $n);
hh_expect_equivalent<~num>($vn[0] / $i);
hh_expect_equivalent<~float>($vf[0] / $i);
hh_expect_equivalent<~float>($vf[0] / $n);
hh_expect_equivalent<~num>($vn[0] / $d);
hh_expect_equivalent<~num>($vi[0] / $d);
hh_expect_equivalent<~float>($vf[0] / $d);
hh_expect_equivalent<~num>($d / $vn[0]);
hh_expect_equivalent<~num>($d / $vi[0]);
hh_expect_equivalent<~float>($d / $vf[0]);
hh_expect_equivalent<dynamic>($d / $d);
// All the expressions above should act like function calls to the correctly
// overloaded function. It's ambiguous what to do in the dynamic case,
// since dynamic = ~nothing, and there isn't an overloded case for nothing.
// One could argue that the return should be nothing, and hence the result
// should just be dynamic.
hh_expect_equivalent<num>(div_int_int($i, $i));
hh_expect_equivalent<float>(div_float_float($f, $f));
hh_expect_equivalent<num>(div_num_num($n, $n));
hh_expect_equivalent<num>(div_num_int($n, $i));
hh_expect_equivalent<float>(div_float_int($f, $i));
hh_expect_equivalent<float>(div_float_num($f, $n));
hh_expect_equivalent<~num>(div_int_int($vi[0], $i));
hh_expect_equivalent<~float>(div_float_float($vf[0], $f));
hh_expect_equivalent<~num>(div_num_num($vn[0], $n));
hh_expect_equivalent<~num>(div_num_int($vn[0], $i));
hh_expect_equivalent<~float>(div_float_int($vf[0], $i));
hh_expect_equivalent<~float>(div_float_num($vf[0], $n));
hh_expect_equivalent<dynamic>(div_num_nothing($vn[0], $d));
hh_expect_equivalent<dynamic>(div_nothing_nothing($d, $d));
} |
hhvm/hphp/hack/test/sound_dynamic/typing/dune | (rule
(alias sound_dynamic_typing_good)
(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/HH_FLAGS)
(glob_files %{project_root}/hack/test/sound_dynamic/typing/*.good.php)
(glob_files %{project_root}/hack/test/sound_dynamic/typing/*.good.php.exp)
(glob_files
%{project_root}/hack/test/sound_dynamic/typing/*.good.php.legacy_decl.exp))
(action
(run
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/sound_dynamic/typing
--program
%{exe:../../../src/hh_single_type_check.exe}
--batch
--in-extension
.good.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)))
(rule
(alias sound_dynamic_typing_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/HH_FLAGS)
(glob_files %{project_root}/hack/test/sound_dynamic/typing/*.bad.php)
(glob_files %{project_root}/hack/test/sound_dynamic/typing/*.bad.php.exp)
(glob_files
%{project_root}/hack/test/sound_dynamic/typing/*.bad.php.legacy_decl.exp))
(action
(run
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/sound_dynamic/typing
--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_good)
(alias sound_dynamic_typing_bad))) |
|
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/duplicate_test.bad.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
function toplevel(vec<int> $vi):int {
return C::A;
}
<<__SupportDynamicType>>
class C {
public function foo(vec<int> $vi):int {
return C::A;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/dynamic_array.bad.php | <?hh
class C {}
function test_dyn_array(dynamic $d, C $c) : void {
$d[1] = $c;
$d[$d] = $c;
$d[] = $c;
$d[$c];
$d[$c] = 1;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/dynamic_array.good.php | <?hh
<<__SupportDynamicType>>
class C1 {}
function test_dyn_array<Tk as arraykey>(
dynamic $d,
C1 $c,
int $i,
string $s,
Tk $tk,
arraykey $ak,
): void {
$a = $d[$i];
hh_expect_equivalent<dynamic>($a);
$a = $d[$s];
hh_expect_equivalent<dynamic>($a);
$a = $d[$d];
hh_expect_equivalent<dynamic>($a);
$a = $d[$tk];
hh_expect_equivalent<dynamic>($a);
$a = $d[$ak];
hh_expect_equivalent<dynamic>($a);
$d[$i] = $c;
$d[$s] = $c;
$d[$d] = $c;
$d[$ak] = $c;
$d[$tk] = $c;
$d[] = $c;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/dynamic_lower_bound_not_stripped.good.php | <?hh
<<__SupportDynamicType>>
function g(int $cs): void {}
function f(bool $b, dynamic $d): void {
$x = Vector{};
if ($b) {
$x[] = $d;
} else {
$x[] = 1;
}
$y = $x[0];
g($y);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/dynamic_unbound.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
function foo(vec<int> $_): void {
/* HH_FIXME[2049] *//* HH_FIXME[4107] */
$x = boo();
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/enforceable_property.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
class C {
private ?int $v;
public function foo<T as supportdyn<mixed>>(~T $x) : ~T { return $x; }
public function bar(?int $v): void {
$this->v = $this->foo($v);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/enforceable_property_02.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
class C {
private ?int $v;
public function foo(?int $x): void {}
public function bar(): void {
$this->foo($this->v);
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/enforceable_static_property_01.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
abstract class C {
abstract public function foo() : Awaitable<~int>;
private static ?int $x;
public async function bar(): Awaitable<~void> {
self::$x = await $this->foo();
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/enforceable_tany.good.php | <?hh
class D {
const type TC = MISSING;
}
type FAKE<T> = T;
/* HH_FIXME[4101] Sadly, yes */
type MISSING = FAKE;
<<__SupportDynamicType>>
class C {
public static MISSING $x = 3;
public static D::TC $y = "A";
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/enumbox.bad.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<file:__EnableUnstableFeatures('upcast_expression')>>
enum E : int as int { A = 3; }
enum F : int as int { B = 5; }
<<__SupportDynamicType>>
class EBox {
public function __construct(public E $item) { }
}
<<__EntryPoint>>
function main():void {
$d = new EBox(E::A);
$dd = $d upcast dynamic;
$dd->item = F::B;
$x = $d->item;
// Now I think I've got an E but I've actually got an F
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/enum_classname.good.php | <?hh // strict
// Copyright 2004-present Facebook. All Rights Reserved.
enum E: string as string {
AA = 'AA';
}
<<__SupportDynamicType>>
class C { }
<<__SupportDynamicType>>
function foo<T as supportdyn<mixed>>(classname<T> $class_name): void { }
function bar<T as supportdyn<mixed>>(T $x):void { }
<<__SupportDynamicType>>
function testit(): void {
bar(new C());
foo(C::class);
bar(E::AA);
foo(E::class);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/enum_class_names.good.php | <?hh
enum class E : int {
int list = 42;
}
<<__SupportDynamicType>>
class C {
public function expectLabel(HH\EnumClass\Label<E, int> $x): void {
}
}
function getC():~C {
return new C();
}
<<__EntryPoint>>
function main(): void {
$c = getC();
$c->expectLabel(#list);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/expected_async_lambda.good.php | <?hh
// Accepted
function test1():void {
$d = makeDynamic();
$f = async function($x) { return $x; };
$d->foo($f);
}
function makeDynamic():dynamic {
return null;
}
// Rejected
function test2():void {
$d = makeDynamic();
$d->foo(async function($x) { return $x; });
$d->foo(function($x) { return $x; });
$d->foo(async function($x) { return 3; });
$d->foo(function($x) { return 3; });
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/expected_dict_push.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
function singleton<Tk as supportdyn<mixed> as arraykey, Tv as supportdyn<mixed> >(~Tk $k, ~Tv $v): ~dict<Tk, Tv> {
return dict[$k => $v];
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/expected_like_lam.good.php | <?hh
class C {
public function foo():string { return "A"; }
}
function returnFun():vec<(function(C):arraykey)> {
return vec[$x ==> $x->foo()];
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/expected_sd_function.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
class D { }
<<__SupportDynamicType>>
class E {
public function foo():D { return new D(); }
}
function expectD(D $n):void { }
function testit():void {
expectSDTfun(($v) ==> {
$x = $v[0]->foo();
// should be an error in check under dynamic
expectD($x);
return $x;
});
}
function expectSDTfun(supportdyn<(function(vec<E>):D)> $f): void { } |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/expected_sd_function.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
class D { }
<<__SupportDynamicType>>
class E {
public function foo():D { return new D(); }
}
function expectSD(supportdyn<mixed> $n):void { }
function testit():void {
expectSDTfun(($v) ==> {
$x = $v[0]->foo();
expectSD($x);
return $x;
});
}
function expectSDTfun(supportdyn<(function(vec<E>):D)> $f): void { } |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/expected_type_error.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__NoAutoDynamic>>
function expect_int(~int $_): void {}
<<__SupportDynamicType>>
class Box<T> {
}
<<__NoAutoDynamic>>
function e<T as supportdyn<mixed>>(~C<Box<T>> $param): ~T {
return 1 upcast dynamic;
}
<<__NoAutoDynamic>>
function get_C() : C<~Box<string>> { return new C<Box<string>>();}
<<__SupportDynamicType>>
class C<+T> {}
<<__NoAutoDynamic>>
function testit(): void {
expect_int(e(get_C()));
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/expected_type_like_call.good.php | <?hh
function makeOptVec(): ~?vec<int> {
return null;
}
<<__SupportDynamicType>>
function foo<Tv1 as supportdyn<mixed>>(Traversable<Tv1> $traversable): void {}
function test(): void {
$options = makeOptVec();
$x = $options ?? vec[];
foo($x);
foo<int>($options ?? vec[]);
foo($options ?? vec[]);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/fixme_deprecated.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
class C {
<<__Deprecated("Do not call me")>>
public static function foo():void { }
public function bar(vec<int> $vi):void {
/* HH_FIXME[4128] */
C::foo();
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/foreach.good.php | <?hh
class C {
public function f(dynamic $d) : dynamic {
foreach ($d as $k => $v) {
if ($d) {
return $v->m();
}
else {
return $k->m();
}
}
foreach ($d as $v) {
return $v->m();
}
return $d;
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/foreach_nonnull_like_any.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
type FAKE<T> = T;
/* HH_FIXME[4101] Sadly, yes */
type MISSING = FAKE;
function getMissing(): ~MISSING {
return "A";
}
function expectLikeInt(~int $x):void { }
function testforeach():void {
$x = getMissing();
if ($x is nonnull) {
foreach ($x as $y) {
expectLikeInt($y);
}
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/foreach_sdt.good.php | <?hh
class C {
public function f() : void {}
}
<<__SupportDynamicType>>
function f(vec<C> $c) : void {
$x = $c[0];
$as = vec[$x]; // x is T on normal pass and dynamic on dyn pass
foreach ($as as $a) {
$a->f();
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/format_string.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
function getStrings():~vec<string> {
return vec["ABC"];
}
<<__SupportDynamicType>>
function getInts():~vec<int> {
return vec[42];
}
<<__SupportDynamicType>>
function getFloats():~vec<float> {
return vec[2.3];
}
<<__SupportDynamicType>>
function getDyn():dynamic {
return 2.4 upcast dynamic;
}
<<__SupportDynamicType>>
function mysprintf(
\HH\FormatString<\PlainSprintf> $fmt,
supportdyn<mixed> ...$fmt_args
)[]: ~string {
return "A";
}
<<__SupportDynamicType>>
function test(~vec<int> $v):void {
$s = getStrings()[0];
$i = getInts()[0];
$f = getFloats()[0];
$d = getDyn();
$t = mysprintf("test %s", $s);
echo $t;
}
<<__SupportDynamicType, __EntryPoint>>
function main():void {
test(vec[]);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/funapp_refine.good.php | <?hh
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
<<__SupportDynamicType>>
function foo(int $x, vec<int> $y): void { }
<<__SupportDynamicType>>
function bar(int $y, ?vec<int> $z):void {
$w = $z ?: vec[];
foo($y, $w);
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/generic_call_supportdyn.good.php | <?hh
<<__SupportDynamicType>>
interface I {
}
<<__SupportDynamicType>>
interface J
<
Tent as supportdyn<mixed> as I
> {
public static function title(
): void;
}
<<__SupportDynamicType>>
trait TR
<
Tent as I,
Tspec as supportdyn<mixed> as J<Tent>
> {
abstract const classname<Tspec> SPEC_CLASS;
public function whereTitle(
): void {
$spec_class = static::SPEC_CLASS;
$spec_class::title();
}
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/generic_constraint_dynamic.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
class C<<<__RequireDynamic>>T as supportdyn<mixed>> {
public function __construct(private T $item) { }
public function get():T {
return $this->item;
}
}
function make<<<__RequireDynamic>>T as supportdyn<mixed>>(T $x): C<T> {
return new C<T>($x);
}
class D { }
function testit():void {
$x = new C<D>(new D());
$y = make<D>(new D());
$a = new C(new D());
$b = make(new D());
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/generic_constraint_dynamic.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<__SupportDynamicType>>
class C<<<__RequireDynamic>>T as supportdyn<mixed>> {
public function __construct(private T $item) { }
public function get():T {
return $this->item;
}
}
function make<<<__RequireDynamic>>T as supportdyn<mixed>>(T $x): C<T> {
return new C<T>($x);
}
function testit():void {
$x = new C<int>(3);
$y = make<string>("A");
$a = new C(3);
$b = make("A");
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/generic_no_require_dynamic.bad.php | <?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
class C<T> {
public function __construct(private T $x) {}
public function get() : T { return $this->x; }
}
<<__SupportDynamicType>>
class D<T> {
public function __construct(private T $x) {}
public function set(T $x) : void { $this->x = $x; }
}
function f() : void {
new C<mixed>(1) upcast dynamic;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/generic_no_require_dynamic.good.php | <?hh
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
class C<T> {
public function __construct(private T $x) {}
public function get() : T { return $this->x; }
public function k((function (T) : T) $f) : T {
return $f($this->x);
}
}
function f() : void {
new C<int>(1) upcast dynamic;
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/generic_params.bad.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
class Box<<<__RequireDynamic>> T> {
public function __construct(private T $item) { }
public function get(): T { return $this->item; }
public function set(T $x):void { $this->item = $x; }
}
<<__SupportDynamicType>>
class SimpleBox<<<__RequireDynamic>> T> {
public function __construct(public T $item) { }
}
function testit():void {
new Box<int>(3) upcast dynamic;
new SimpleBox<string>("a") upcast dynamic;
new KeyBox<int>(3) upcast dynamic;
}
<<__SupportDynamicType>>
interface Getter<<<__RequireDynamic>> +T> {
public function get(): T;
}
<<__SupportDynamicType>>
class AnotherBox<<<__RequireDynamic>> T> implements Getter<vec<T>> {
public function __construct(private vec<T> $item) { }
public function get(): vec<T> { return $this->item; }
public function set(T $x): void { $this->item = vec[$x]; }
}
<<__SupportDynamicType>>
class KeyBox<<<__RequireDynamic>> T as arraykey> {
public function __construct(private T $item) { }
public function get(): T { return $this->item; }
public function set(T $x):void { $this->item = $x; }
} |
PHP | hhvm/hphp/hack/test/sound_dynamic/typing/generic_params.good.php | <?hh
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
<<file:__EnableUnstableFeatures('upcast_expression')>>
<<__SupportDynamicType>>
class Box<<<__RequireDynamic>> T> {
public function __construct(private T $item) { }
public function get(): T { return $this->item; }
public function set(T $x):void { $this->item = $x; }
}
<<__SupportDynamicType>>
class SimpleBox<<<__RequireDynamic>> T> {
public function __construct(public T $item) { }
}
<<__SupportDynamicType>>
interface Getter<<<__RequireDynamic>> +T> {
public function get(): T;
}
<<__SupportDynamicType>>
class ROBox<<<__RequireDynamic>> +T> implements Getter<vec<T>> {
public function __construct(private vec<T> $item) { }
public function get(): vec<T> { return $this->item; }
}
<<__SupportDynamicType>>
class KeyBox<<<__RequireDynamic>> T as arraykey> {
public function __construct(private T $item) { }
public function get(): T { return $this->item; }
public function set(T $x):void { $this->item = $x; }
}
function testit(Getter<float> $g):void {
new Box(3) upcast dynamic;
new Box(true) upcast dynamic;
new SimpleBox("a") upcast dynamic;
new KeyBox<arraykey>(3) upcast dynamic;
$g upcast dynamic;
} |
hhvm/hphp/hack/test/sound_dynamic/typing/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 --config pessimise_builtins=true --enable-supportdyn-hint --union-intersection-type-hints --like-type-hints
--config enable_no_auto_dynamic=true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.