Skip to content

Commit

Permalink
test: add test for subtracted mixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan committed May 11, 2024
1 parent 321432a commit a23a9f8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -772,13 +772,37 @@ public function testMixed(): void
'Cannot access offset 5 on T of mixed.',
11,
],
[
'Cannot access offset 5 on T of mixed.',
12,
],
[
'Cannot access offset 5 on T of mixed.',
18,
],
[
'Cannot access offset 5 on mixed.',
16,
24,
],
[
'Cannot access offset 5 on mixed.',
25,
],
[
'Cannot access offset 5 on mixed.',
31,
],
[
'Cannot access offset 5 on mixed.',
37,
],
[
'Cannot access offset 5 on mixed.',
38,
],
[
'Cannot access offset 5 on mixed.',
21,
44,
],
]);
}
Expand Down
24 changes: 24 additions & 0 deletions tests/PHPStan/Rules/Arrays/data/offset-access-mixed.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,38 @@
function foo(mixed $a): void
{
var_dump($a[5]);
isset($a[5]); // error, because including object type

if (is_object($a)) {
throw new \Error();
}

var_dump($a[5]); // error
isset($a[5]); // ok, because object type, which throws an error do not implement ArrayAccess, is subtracted
}

function foo2(mixed $a): void
{
var_dump($a[5]);
isset($a[5]);

if (is_object($a)) {
throw new \Error();
}

var_dump($a[5]); // error
isset($a[5]); // ok, because object type, which throws an error do not implement ArrayAccess, is subtracted
}

function foo3($a): void
{
var_dump($a[5]);
isset($a[5]);

if (is_object($a)) {
throw new \Error();
}

var_dump($a[5]); // error
isset($a[5]); // ok, because object type, which throws an error do not implement ArrayAccess, is subtracted
}

0 comments on commit a23a9f8

Please sign in to comment.