From 8c1dfc1afb3f381c8e50befe38e8abc581c67db2 Mon Sep 17 00:00:00 2001
From: Ondrej Mirtes <ondrej@mirtes.cz>
Date: Fri, 4 Mar 2022 10:28:12 +0100
Subject: [PATCH] ArrayType::traverse() - create empty ConstantArrayType in
 case of never

---
 src/Type/ArrayType.php                   | 4 ++++
 tests/PHPStan/Analyser/data/generics.php | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php
index 0c8f6da9f0..8d7d323b20 100644
--- a/src/Type/ArrayType.php
+++ b/src/Type/ArrayType.php
@@ -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);
 		}
 
diff --git a/tests/PHPStan/Analyser/data/generics.php b/tests/PHPStan/Analyser/data/generics.php
index 2732c34053..45e522e954 100644
--- a/tests/PHPStan/Analyser/data/generics.php
+++ b/tests/PHPStan/Analyser/data/generics.php
@@ -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);