diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index 24d886f990..65a6886bab 100644 --- a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php @@ -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, ], ]); } diff --git a/tests/PHPStan/Rules/Arrays/data/offset-access-mixed.php b/tests/PHPStan/Rules/Arrays/data/offset-access-mixed.php index 9f3300ce65..cea536bf60 100644 --- a/tests/PHPStan/Rules/Arrays/data/offset-access-mixed.php +++ b/tests/PHPStan/Rules/Arrays/data/offset-access-mixed.php @@ -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 }