language
stringlengths 0
24
| filename
stringlengths 9
214
| code
stringlengths 99
9.93M
|
---|---|---|
hhvm/hphp/hack/test/shallow_class_diff/private_member_added.php.after | <?hh
class C {
private ?int $x;
private static ?int $x;
private function f(): void {}
private static function f(): void {}
} |
|
PHP | hhvm/hphp/hack/test/shallow_class_diff/private_member_removed.php | <?hh
class C {
private ?int $x;
private static ?int $y;
private function f(): void {}
private static function g(): void {}
} |
PHP | hhvm/hphp/hack/test/shape_analysis/codemod/argument.php | <?hh
function f(): void {
$d = dict['a' => true]; // Report an allocation result here
inspect($d); // Don't report a result here due to argument
} |
PHP | hhvm/hphp/hack/test/shape_analysis/codemod/awaitable.php | <?hh
async function f(): Awaitable<dict<string, mixed>> {
// ^
// |
// TODO(T140415114): at column 21 expect `Awaitable<shape()>`
// instead produces `shape()`
return dict[];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/codemod/darray_type_hint.php | <?hh
function f(): darray<string, mixed> {
return darray['a' => 42];
}
function g(): darray<string, mixed> {
return dict['a' => 42];
}
function h(): dict<string, mixed> {
return darray['a' => 42];
} |
hhvm/hphp/hack/test/shape_analysis/codemod/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/codemod/HH_FLAGS
(glob_files %{project_root}/hack/test/shape_analysis/codemod/*.php)
(glob_files
%{project_root}/hack/test/shape_analysis/codemod/*.php.exp))
(action
(run
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/shape_analysis/codemod
--program
%{exe:../../../src/hh_single_type_check.exe}
--in-extension
.php
--flags
--union-intersection-type-hints
--shape-analysis
codemod:global
--error-format
plain)))
(alias
(name runtest)
(deps
(alias shape_analysis))) |
|
PHP | hhvm/hphp/hack/test/shape_analysis/codemod/incomplete.php | <?hh
function complete(): void {
dict['a' => 42];
}
class :div {
public function __construct(
dict<string, mixed> $attributes,
vec_or_dict<mixed> $children,
string $file,
int $line
): void {}
}
function incomplete(): void {
<div />;
dict['a' => 42];
<div />;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/codemod/multi.php | <?hh
function f(): void {
dict['a' => 42, 'b' => true];
dict['c' => 42];
}
function g(): void {
dict['a' => 42, 'b' => true];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/dump_constraints/call.php | <?hh
function f(): void {
$d1 = dict['a' => 42];
$d2 = dict['b' => 42];
g($d1, $d2);
}
function g(dict<string,mixed> $d1, dict<string,mixed> $d2): void {
h($d1);
}
function h(dict<string,mixed> $d) : void {
$d['c'] = 42;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/dump_constraints/class_constant2.php | <?hh
class C {
const dict<string, mixed> DICT = dict['a' => 42];
}
function main(): void {
idx(C::DICT, 'b');
} |
PHP | hhvm/hphp/hack/test/shape_analysis/dump_constraints/class_constant2b.php | <?hh
class C {
const dict<string, mixed> DICT = dict['a' => 42];
}
function main(): void {
C::DICT['b'];
} |
hhvm/hphp/hack/test/shape_analysis/dump_constraints/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/dump_constraints/HH_FLAGS
(glob_files %{project_root}/hack/test/shape_analysis/dump_constraints/*.php)
(glob_files %{project_root}/hack/test/shape_analysis/dump_constraints/*.php.exp))
(action
(run
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/shape_analysis/dump_constraints
--program
%{exe:../../../src/hh_single_type_check.exe}
--in-extension
.php
--flags
--union-intersection-type-hints
--shape-analysis
dump:global
--error-format
plain)))
(alias
(name runtest)
(deps
(alias shape_analysis))) |
|
PHP | hhvm/hphp/hack/test/shape_analysis/dump_constraints/idx.php | <?hh
function idx_with_and_without_opt(dict<string, mixed> $d): void {
idx($d, 'x');
idx($d, 'y', 0);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/dump_constraints/idx2.php | <?hh
function idx_ife(dict<string, mixed> $d, bool $b): void {
if ($b) {
$d['a'];
idx($d, 'b');
$d['c1'];
idx($d, 'd1');
} else {
$d['a'];
idx($d, 'b');
$d['c2'];
idx($d, 'd2');
}
} |
PHP | hhvm/hphp/hack/test/shape_analysis/dump_constraints/literals.php | <?hh
function dict_constraints(): void {
dict['a' => 42, 'b' => true];
}
function darray_constraints(): void {
darray['a' => 42, 'c' => 'Value'];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/dump_constraints/parameter2.php | <?hh
// No constraints should be generated because we only consider dicts with
// strings keys at the moment
function f(dict<arraykey, mixed> $param): void {} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/await2.php | <?hh
async function f(Awaitable<dict<string, int>> $d): Awaitable<void> {
$d = await $d;
$d['k'] = 42;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/best_effort.php | <?hh
class :div {
public function __construct(
dict<string, mixed> $attributes,
vec_or_dict<mixed> $children,
string $file,
int $line
): void {}
}
function f(): void {
dict['a' => 42];
<div />; // XML is not yet supported
$d = dict['b' => 42];
<div />; // XML is not yet supported
if (42 === 24) {
$d['c'];
} else {
$d['d'];
}
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/birufcating_array.php | <?hh
function f(): void {
$d = dict['a' => 42];
$e = $d;
$k = 'b';
$e['c'] = 'apple';
$d[$k] = 3.14; // This should cause $e to be invalidated as well.
inspect($e);
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/bop.php | <?hh
function test_plus(dict<string, int> $d): void {
$d['a'] + $d['b'];
inspect($d);
}
function test_minus(dict<string, int> $d): void {
$d['a'] - $d['b'];
inspect($d);
}
function test_star(dict<string, int> $d): void {
$d['a'] * $d['b'];
inspect($d);
}
function test_slash(dict<string, int> $d): void {
$d['a'] / $d['b'];
inspect($d);
}
function test_eqeq(dict<string, int> $d): void {
$d['a'] == $d['b'];
inspect($d);
}
function test_eqeqeq(dict<string, int> $d): void {
$d['a'] === $d['b'];
inspect($d);
}
function test_starstar(dict<string, int> $d): void {
$d['a'] ** $d['b'];
inspect($d);
}
function test_diff(dict<string, int> $d): void {
$d['a'] != $d['b'];
inspect($d);
}
function test_ampamp(dict<string, bool> $d): void {
$d['a'] && $d['b'];
inspect($d);
}
function test_barbar(dict<string, bool> $d): void {
$d['a'] || $d['b'];
inspect($d);
}
function test_lt(dict<string, int> $d): void {
$d['a'] < $d['b'];
inspect($d);
}
function test_lte(dict<string, int> $d): void {
$d['a'] <= $d['b'];
inspect($d);
}
function test_gt(dict<string, int> $d): void {
$d['a'] > $d['b'];
inspect($d);
}
function test_gte(dict<string, int> $d): void {
$d['a'] >= $d['b'];
inspect($d);
}
function test_dot(dict<string, string> $d): void {
$d['a'] . $d['b'];
inspect($d);
}
function test_amp(dict<string, int> $d): void {
$d['a'] & $d['b'];
inspect($d);
}
function test_bar(dict<string, int> $d): void {
$d['a'] | $d['b'];
inspect($d);
}
function test_ltlt(dict<string, int> $d): void {
$d['a'] << $d['b'];
inspect($d);
}
function test_gtgt(dict<string, int> $d): void {
$d['a'] >> $d['b'];
inspect($d);
}
function test_percent(dict<string, int> $d): void {
$d['a'] % $d['b'];
inspect($d);
}
function test_xor(dict<string, int> $d): void {
$d['a'] ^ $d['b'];
inspect($d);
}
function test_cmp(dict<string, int> $d): void {
$d['a'] <=> $d['b'];
inspect($d);
}
function test_eq1(dict<string, int> $d): void {
$d['a'] = $d['b'];
}
function test_eq2(dict<string, int> $d): void {
$d['a'] = 42;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/branching_has1.php | <?hh
// solution is correct: empty shape() with no keys
function foo(dict<string, mixed> $d)
// solution is correct: shape(?a => mixed, ?b => mixed)
: dict<string, mixed> {
if (true === false) {
$d['a'] = 1;
inspect($d);
} else {
$d['b'] = 1;
inspect($d);
}
return $d;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/branching_has_then_needs1.php | <?hh
// expected parameter hint: shape()
// we infer incorrect parameter hint: shape('a' => mixed, 'b' => mixed)
function foo(dict<string, mixed> $d)
// inferred return hint is correct: shape(?a => mixed, ?b => mixed)
: dict<string, mixed> {
if (true === false) {
$d['a'] = 1;
$d['a'];
inspect($d);
} else {
$d['b'] = 1;
$d['b'];
inspect($d);
}
return $d;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/branching_needs1_wip.php | <?hh
// expect shape() with no keys
function foo(dict<string, mixed> $d)
// TODO(T136668856): expect shape(a => mixed, b => mixed)
: dict<string, mixed> {
if (true === false) {
$d['a'];
inspect($d);
} else {
$d['b'];
inspect($d);
}
return $d;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/branching_needs_then_has1_wip.php | <?hh
// solution is correct: empty shape() with no keys
function foo(dict<string, mixed> $d)
: dict<string, mixed> {
if (true === false) {
$d['a'];
$d['a'] = 1;
inspect($d);
} else {
$d['b'];
$d['b'] = 1;
inspect($d);
}
return $d;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/break.php | <?hh
function f(): void {
$b = true;
$d = dict[];
while ($b) {
$d['a'] = true;
inspect($d);
break;
$d['b'] = 42;
inspect($d);
}
$d['c'] = 42.0;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/break2.php | <?hh
function f(): void {
$b = true;
$d = dict[];
while ($b) {
$d['a'] = true;
inspect($d);
if ($b) { break; }
$d['b'] = 42;
inspect($d);
}
$d['c'] = 42.0;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/collection_access.php | <?hh
function vec_access(): void {
$v = vec[dict['a' => 42], dict['b' => 'apple']];
$w = $v;
$v[0] = dict['c' => 42.0];
inspect($v[0]); // Expect 'c' to appear here
inspect($w[0]); // But not here
}
function vector_access(): void {
$v = Vector {dict['a' => 42], dict['b' => 'apple']};
$w = $v;
$v[0] = dict['c' => 42.0];
inspect($v[0]); // Expect 'c' to appear here
inspect($w[0]); // And here
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/collection_append.php | <?hh
function vec_append(): void {
$v = vec[dict['a' => 42]];
$v[] = dict['b' => 42.0];
inspect($v);
}
function vector_append(): void {
$v = Vector {dict['a' => 42]};
$v[] = dict['b' => 42.0];
inspect($v);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/collection_literal.php | <?hh
function vec_test(): void {
vec[dict['a' => 42], dict['b' => true]];
}
function keyset_test(): void {
keyset['a', 'b']; // Tests that no errors are produced
}
function dict_test(): void {
dict['oa_' => dict['a' => 42], 'ob' => dict['b' => true]];
}
function vector_test(): void {
Vector {dict['a' => 42], dict['b' => true]};
}
function set_test(): void {
Set {'a', 'b'}; // Tests that no errors are produced
}
function map_test(): void {
Map {'oa' => dict['a' => 42], 'ob' => dict['b' => true]};
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/constant_keys.php | <?hh
class C {
const string K1 = "key1";
const string K2 = "key2";
}
class D {
const string K1 = "key3";
}
function f(): void {
$d = dict[C::K1 => 42, D::K1 => "apple"];
$d[C::K2] = 42.0;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/continue.php | <?hh
function f(): void {
$b = true;
$d = dict[];
while ($b) {
$d['a'] = true;
inspect($d);
continue;
$d['b'] = 42;
inspect($d);
}
$d['c'] = 42.0;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/definite_optional2.php | <?hh
function f(): void {
$d = dict[];
$b = true;
if ($b) {
$d['a'] = 'apple';
}
$d['a'] = 'apple';
inspect($d);
} |
hhvm/hphp/hack/test/shape_analysis/simplify_constraints/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/simplify_constraints/HH_FLAGS
(glob_files %{project_root}/hack/test/shape_analysis/simplify_constraints/*.php)
(glob_files
%{project_root}/hack/test/shape_analysis/simplify_constraints/*.php.exp))
(action
(run
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/shape_analysis/simplify_constraints
--program
%{exe:../../../src/hh_single_type_check.exe}
--in-extension
.php
--flags
--union-intersection-type-hints
--shape-analysis
simplify:global
--error-format
plain)))
(alias
(name runtest)
(deps
(alias shape_analysis))) |
|
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/dynamic_access2.php | <?hh
function f(string $dynamic_key): void {
$d = dict['a' => 42];
$d['b'] = true;
$d[$dynamic_key];
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/dynamic_access3.php | <?hh
function f(dict<string, mixed> $d, string $dynamic_key): void {
$d['b'] = true;
$d[$dynamic_key];
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/dynamic_access4.php | <?hh
function f(bool $b, string $dynamic_key): void {
$d = dict['a' => 42];
$d['b'] = true;
if ($b) {
$d[$dynamic_key];
}
$d['c'] = 3.14;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/entity_assignment2.php | <?hh
function f(): void {
$x = dict[];
$y = 42; // Irrelevant
$z = $x;
$z['a'];
inspect($z);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/enum_keys.php | <?hh
enum C : string {
K1 = "key1";
K2 = "key2";
}
enum D : string {
K1 = "key3";
}
function f(): void {
$d = dict[C::K1 => 42, D::K1 => "apple"];
$d[C::K2] = 42.0;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/foreach2.php | <?hh
function f(): void {
$v = vec[dict['a' => 42]];
foreach ($v as $d) {
$d['b'] = true;
inspect($d);
}
inspect($v[0]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/foreach3.php | <?hh
function f(): void {
$v = vec[dict['a' => 42]];
foreach ($v as $d) {
$v[] = dict['b' => $d['a']];
inspect($v[0]);
}
inspect($v[0]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/foreach4.php | <?hh
function f(vec<bool> $v): void {
$d = dict['d' => 42];
$e = dict['e' => 'hi'];
$f = dict['f' => 42.0];
foreach ($v as $val) {
$f['fixpoint'] = $val;
inspect($f);
$f = $e;
$e = $d;
}
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/identical_keys_different_shapes.php | <?hh
function f(dict<string, mixed> $d1, dict<string, mixed> $d2): void {
$d1['k'] = 42;
$d2['k'] = true;
inspect($d1);
inspect($d2);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/idx.php | <?hh
function idx_with_and_without_opt(dict<string, mixed> $d): void {
idx($d, 'x');
idx($d, 'y', 0);
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/idx2.php | <?hh
function idx_ife(dict<string, mixed> $d, bool $b): void {
if ($b) {
$d['a'];
idx($d, 'b');
$d['c1'];
idx($d, 'd1');
} else {
$d['a'];
idx($d, 'b');
$d['c2'];
idx($d, 'd2');
}
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/if.php | <?hh
function f(): void {
if (true) {
dict['a' => 42];
} else {
dict['b' => true];
}
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/if2.php | <?hh
function f(): void {
$d = dict['a' => 42];
$c = true;
if ($c) {
$d['b'] = 'hi';
inspect($d);
} else {
$d['c'] = true;
inspect($d);
}
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/if3.php | <?hh
function f(): void {
$b = true;
if ($b) {
$d = dict['a' => 42];
} else {
$d = dict['b' => true];
}
$d['c'] = 'apple';
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/if4.php | <?hh
function f(): void {
$b = true;
if ($b) {
if ($b) {
$d = dict['a' => 42];
} else {
$d = dict['b' => 42.0];
}
} else {
if ($b) {
$d = dict['c' => true];
} else {
if ($b) {
$d = dict['d' => false];
} else {
$d = dict['e' => 42];
}
}
}
$d['f'] = 42;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/if5.php | <?hh
function f(): void {
$d = dict[];
$b = true;
if ($b) {
$d = dict[];
}
$d['a'] = 42;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/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(C $c): void {
$d = dict['a' => 0];
f(inout $d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/is.php | <?hh
class C {}
function f(mixed $m): void {
$d = dict[];
if ($m is int) {
$d['k'] = 42;
}
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/literals.php | <?hh
function dict_constraints(): void {
dict['a' => 42, 'b' => true];
}
function darray_constraints(): void {
darray['a' => 42, 'c' => 'Value'];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/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/simplify_constraints/no_shapes_expected.php | <?hh
interface I {}
function foo(
I $i // TODO(T140068390): should not infer a shape
): void {}
async function gen_void():
Awaitable<void> {} // TODO(T140068390): should not infer a shape |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/optional_backwards.php | <?hh
function f(dict<string, mixed> $d): void {
$b = true;
if ($b) {
$d['a'];
idx($d,'b');
$d['c'];
} else {
idx($d,'a');
idx($d,'b');
$d['c'];
}
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/optional_definite.php | <?hh
function f(): void {
$d = dict[];
$b = true;
if ($b) {
$d['a'] = 42;
}
inspect($d);
$d['a'] = 24;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/parameter2.php | <?hh
function f(int $i, dict<string, int> $d): void {
$d['k'] = $i;
inspect($d);
$d['l'] = $i;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/return1.php | <?hh
// Report a shape type at the return type hint
function f(): dict<string, mixed> {
return dict['a' => 42];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/return2.php | <?hh
// Empty returns don't make the analysis crash
function f(): void {
while (true) {
return;
}
return;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/return3.php | <?hh
function multi_return(): dict<string, mixed> {
$b = true;
if ($b) {
return dict['a' => 42];
}
return dict['b' => $b];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/switch.php | <?hh
function f(): void {
$d = dict[];
$i = 42;
switch ($i) {
case 0:
$d['a'] = 42;
inspect($d);
break;
case 1:
$d['b'] = 'hi';
inspect($d);
break;
default:
$d['c'] = false;
inspect($d);
}
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/switch2.php | <?hh
function f(): void {
$i = 42;
switch ($i) {
case 0:
$d = dict[];
break;
case 1:
$d = dict['b' => 42];
break;
default:
$d = dict['c' => true];
}
$d['a'] = 'hey';
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/switch3.php | <?hh
function f(): void {
$d = dict[];
$i = 42;
switch ($i) {
case 0:
$d['a'] = 42;
inspect($d);
break;
case 1:
$d = dict[];
$d['b'] = 'hi';
inspect($d);
break;
default:
$d['c'] = false;
inspect($d);
}
$d['d'] = 3.14;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/switch4.php | <?hh
function f(): void {
$d = dict[];
$i = 42;
switch ($i) {
case 0:
$d['a'] = 42;
inspect($d);
break;
case 1:
$d = dict[];
$d['b'] = 'hi';
inspect($d);
// FALLTHROUGH
default:
$d['c'] = false;
inspect($d);
}
$d['d'] = 3.14;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/switch5.php | <?hh
function f(): void {
$d = dict[];
switch (42) {
case 0:
$d['a'];
break;
case 1:
$d['b1'];
$d['b2'] = 42;
break;
default:
$d['c1'] = 42;
$d['c2'];
}
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/tuple.php | <?hh
function f(): void {
$d = tuple(dict['a' => 42], dict['b' => 'string']);
inspect($d[0]);
inspect($d[1]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/tuple2.php | <?hh
function f(string $key): void {
$d = tuple(dict['a' => 42], dict['b' => 'string']);
$d[0][$key];
inspect($d[0]);
inspect($d[1]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/unpack.php | <?hh
class C {
public function splat_m(num ...$n): void {}
}
function main1(C $c): void { // TODO: too conservative, we don't need to invalidate splatted dicts
$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]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/uop.php | <?hh
function test_utild(dict<string, int> $d): void {
~$d['a'];
inspect($d);
}
function test_unot(dict<string, bool> $d): void {
!$d['a'];
inspect($d);
}
function test_uplus(dict<string, int> $d): void {
+$d['a'];
inspect($d);
}
function test_uminus(dict<string, int> $d): void {
-$d['a'];
inspect($d);
}
function test_uincr(dict<string, int> $d): void {
--$d['a'];
inspect($d);
}
function test_udecr(dict<string, int> $d): void {
--$d['a'];
inspect($d);
}
function test_upincr(dict<string, int> $d): void {
$d['a']++;
inspect($d);
}
function test_updecr(dict<string, int> $d): void {
$d['a']--;
inspect($d);
}
function test_usilence(dict<string, int> $d): void {
@$d['a'];
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/while.php | <?hh
function f(): void {
$d = dict['a' => 42];
$b = false;
while ($b) {
$d['b'] = 'hi';
inspect($d);
}
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/while2.php | <?hh
function f(): void {
$d = dict['a' => 42];
$b = false;
while ($b) {
$d = dict['b' => 'h'];
$d['c'] = true;
inspect($d);
}
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/while3.php | <?hh
function f(): void {
$d = dict['a' => true];
$b = false;
while ($b) {
$d = dict['b' => 'h'];
}
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/while4.php | <?hh
function f(): void {
$d = dict['a' => 42];
$b = false;
while ($b) {
$d['c'] = false;
$d = dict['b' => 'h'];
}
} |
PHP | hhvm/hphp/hack/test/shape_analysis/simplify_constraints/while5.php | <?hh
function f(): void {
$b = false;
$d = dict['d' => 42];
$e = dict['e' => 'hi'];
$f = dict['f' => 42.0];
while ($b) {
$f['fixpoint'] = true;
inspect($f);
$f = $e;
$e = $d;
}
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/approximate_2.php | <?hh
class K {
public function meth(mixed $_): void {}
}
<<__EntryPoint>>
function foo(): void {
$k = new K();
$k->meth(dict[]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/call_assign.php | <?hh
function f(): void {
g(dict['a' => 42]);
}
function g(dict<string,mixed> $d): void {
$d['b'] = true;
inspect($d);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/call_assign_2.php | <?hh
function f(): void {
$d = dict['a' => 42];
g($d);
inspect($d);
}
function g(dict<string,mixed> $d): void {
$d['b'] = true;
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/call_simple.php | <?hh
function f(): void {
g(dict['a' => 42]);
}
function g(dict<string,mixed> $d): void {
$d['b'];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/class_constant2.php | <?hh
class C {
const dict<string, mixed> DICT = dict['a' => 42];
}
function main(): void {
idx(C::DICT, 'b');
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/class_constant2b.php | <?hh
class C {
const dict<string, mixed> DICT = dict['a' => 42];
}
function main(): void {
C::DICT['b'];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/class_constants3.php | <?hh
class C {
const dict<string, mixed> DICT = dict['a' => 42];
}
class D extends C {
}
function main(): void {
idx(D::DICT, 'b');
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/class_constants4.php | <?hh
class C {
const dict<string, mixed> DICT = dict['a' => 42];
}
class D extends C {
}
class E extends C {
const dict<string, mixed> DICT = dict['b' => true];
}
function main(): void {
idx(C::DICT, 'c');
idx(D::DICT, 'd');
idx(E::DICT, 'e');
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/class_constants5.php | <?hh
class C {
const dict<string, mixed> DICT = dict['a' => 42];
}
class D extends C {
}
class E extends D {
}
function main(): void {
idx(E::DICT, 'b');
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/class_constants6.php | <?hh
class C {
const dict<string, mixed> DICT = dict['a' => 42];
}
class D extends C {
const dict<string, mixed> DICT = dict['b' => 42];
}
class E extends D {
const dict<string, mixed> DICT = dict['c' => 42];
}
function main(): void {
idx(E::DICT, 'd');
idx(D::DICT, 'e');
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/class_constants7.php | <?hh
class C {
const dict<string, mixed> DICT = dict["a" => 2];
}
class D extends C {
const dict<string, mixed> DICT = dict["b" => "apple"];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/class_constants8_wip.php | <?hh
class C1 {
const dict<string, mixed> DICT = dict['a' => 2];
// type incorrectly solved to: shape('a' => int, ?'extra' => mixed)
// better to not convert to dict,
}
function fn(): void {
C1::DICT['extra']; // OutOfBoundsException
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/class_constants9.php | <?hh
class C {
const dict<string, mixed> DICT = dict['a' => 42];
}
class D extends C {
const dict<string, mixed> DICT = dict['a' => 42];
}
class E extends D {}
function main(): void {
idx(E::DICT, 'b');
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/const1.php | <?hh
const dict<string, mixed> DICT = dict['a' => 42];
function main(): void {
DICT['b']; // out of bounds T136763758
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/const2.php | <?hh
const dict<string, mixed> DICT = dict['a' => 42];
function main(): void {
DICT['b1']; // out of bounds T136763758
DICT['b2'];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/const3.php | <?hh
const dict<string, mixed> DICT1 = dict['a' => 42];
const dict<string, mixed> DICT2 = dict['a' => true];
function main(): void {
DICT1['b']; // out of bounds T136763758
DICT2['b'];
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/const_classname1_wip.php | <?hh
class Foo {
const dict<string, mixed> DICT = dict[]; // expect key ?'b'
}
function f(classname<Foo> $the_class_name): void {
$the_class_name::DICT['b']; // should be Shapes::idx
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/const_classname2_wip.php | <?hh
class Foo {
const dict<string, mixed> DICT = dict[]; // expect key ?'b'
}
class Bar extends Foo {
const dict<string, mixed> DICT = dict[]; // expect key ?'b'
}
function f(classname<Foo> $the_class_name): void {
$the_class_name::DICT['b'];
}
function main(classname<Bar> $the_class_name): void {
f(Bar::class);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/const_parent.php | <?hh
class TheParent {
const dict<string, string> DICT = dict["a" => "2"]; // expect ?'b' key
}
class TheChild extends TheParent {
public static function foo(): void {
parent::DICT['b']; // out of bounds T136763758
}
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/const_self.php | <?hh
class Foo {
const dict<string, string> DICT = dict["a" => "2"]; // expect ?'b' key
public static function foo(): void {
self::DICT['b']; // out of bounds T136763758
}
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/const_static.php | <?hh
class Foo {
const dict<string, string> DICT = dict["a" => "2"]; // expect ?'b' key
public static function foo(): void {
static::DICT['b']; // out of bounds T136763758
}
} |
hhvm/hphp/hack/test/shape_analysis/solve_constraints/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/solve_constraints/HH_FLAGS
(glob_files %{project_root}/hack/test/shape_analysis/solve_constraints/*.php)
(glob_files
%{project_root}/hack/test/shape_analysis/solve_constraints/*.php.exp))
(action
(run
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/shape_analysis/solve_constraints
--program
%{exe:../../../src/hh_single_type_check.exe}
--in-extension
.php
--flags
--union-intersection-type-hints
--shape-analysis
solve:global
--error-format
plain)))
(alias
(name runtest)
(deps
(alias shape_analysis))) |
|
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/dynamic.php | <?hh
function f(dict<string, mixed> $d) : void {
$x = 'a';
$d[$x];
}
function main(): void {
f(dict['a' => 42]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/dynamic2.php | <?hh
function f(dict<string, mixed> $d): void {
$d['b'];
}
function main(): void {
$x = 'a';
f(dict[$x => 42]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/forward1.php | <?hh
function f(dict<string, mixed> $d): void {
idx($d, 'b');
}
function main(): void {
f(dict['a' => 42]);
} |
PHP | hhvm/hphp/hack/test/shape_analysis/solve_constraints/forward2.php | <?hh
function f(dict<string, mixed> $d): void {
idx($d, 'b');
}
function g(): void {
f(dict['a' => 42]);
}
function h(): void {
f(dict['a' => true]);
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.