Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,10 @@ private function getTypeFromArrayDimFetch(
throw new ShouldNotHappenException();
}

if ($offsetAccessibleType instanceof NeverType) {
return $offsetAccessibleType;
}

if (!$offsetAccessibleType->isArray()->yes() && (new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes()) {
Copy link
Contributor Author

@staabm staabm Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before this PR we ran into this offsetGet-method-call logic which turned the Never into a Error.

return $this->getType(
new MethodCall(
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/data/bug-9307.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function test(): void
}
}

assertType('array', $objects);
assertType('array<int, Bug9307\Item>', $objects);

$this->acceptObjects($objects);
}
Expand Down
Loading