Skip to content

Commit d7ba1e3

Browse files
staabmondrejmirtes
authored andcommitted
More precise array-item types in loops
1 parent 4c2c1e2 commit d7ba1e3

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Analyser/MutatingScope.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,10 @@ private function getTypeFromArrayDimFetch(
18531853
throw new ShouldNotHappenException();
18541854
}
18551855

1856+
if ($offsetAccessibleType instanceof NeverType) {
1857+
return $offsetAccessibleType;
1858+
}
1859+
18561860
if (!$offsetAccessibleType->isArray()->yes() && (new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes()) {
18571861
return $this->getType(
18581862
new MethodCall(

tests/PHPStan/Analyser/data/bug-9307.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function test(): void
3131
}
3232
}
3333

34-
assertType('array', $objects);
34+
assertType('array<int, Bug9307\Item>', $objects);
3535

3636
$this->acceptObjects($objects);
3737
}

0 commit comments

Comments
 (0)