Skip to content

Commit

Permalink
ArrayType::traverse() - create empty ConstantArrayType in case of never
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 4, 2022
1 parent a84465b commit 8c1dfc1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Type/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ public function traverse(callable $cb): Type
$itemType = $cb($this->itemType);

if ($keyType !== $this->keyType || $itemType !== $this->itemType) {
if ($keyType instanceof NeverType && $itemType instanceof NeverType) {
return new ConstantArrayType([], []);
}

return new self($keyType, $itemType);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/data/generics.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ public function returnStatic(): self
function () {
$stdEmpty = new StdClassCollection([]);
assertType('PHPStan\Generics\FunctionsAssertType\StdClassCollection<*NEVER*, *NEVER*>', $stdEmpty);
assertType('array<*NEVER*, *NEVER*>', $stdEmpty->getAll());
assertType('array{}', $stdEmpty->getAll());

$std = new StdClassCollection([new \stdClass()]);
assertType('PHPStan\Generics\FunctionsAssertType\StdClassCollection<int, stdClass>', $std);
Expand Down

0 comments on commit 8c1dfc1

Please sign in to comment.