diff --git a/src/Type/IntersectionType.php b/src/Type/IntersectionType.php index 2e5514dc020..05b6a14753f 100644 --- a/src/Type/IntersectionType.php +++ b/src/Type/IntersectionType.php @@ -981,7 +981,12 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $uni } } - if ($this->isList()->yes() && $this->getIterableValueType()->isArray()->yes()) { + if ( + $this->isList()->yes() + && $offsetType !== null + && $offsetType->toArrayKey()->isInteger()->yes() + && $this->getIterableValueType()->isArray()->yes() + ) { $result = TypeCombinator::intersect($result, new AccessoryArrayListType()); } diff --git a/tests/PHPStan/Analyser/nsrt/bug-10089.php b/tests/PHPStan/Analyser/nsrt/bug-10089.php index 21122cdfc33..01aafa9790e 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-10089.php +++ b/tests/PHPStan/Analyser/nsrt/bug-10089.php @@ -11,8 +11,10 @@ class Test protected function create_matrix(int $size): array { $size = min(8, $size); + assertType('int', $size); $matrix = []; for ($i = 0; $i < $size; $i++) { + assertType('int<0, 7>', $i); $matrix[] = array_fill(0, $size, 0); } diff --git a/tests/PHPStan/Analyser/nsrt/bug-13629.php b/tests/PHPStan/Analyser/nsrt/bug-13629.php new file mode 100644 index 00000000000..a7ca04defac --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-13629.php @@ -0,0 +1,38 @@ +> $xsdFiles + * @param array> $groupedByNamespace + * @param array> $extraNamespaces + */ +function test(array $xsdFiles, array $groupedByNamespace, array $extraNamespaces): void { + foreach ($extraNamespaces as $mergedNamespace) { + if (count($mergedNamespace) < 2) { + continue; + } + + $targetNamespace = end($mergedNamespace); + if (!isset($groupedByNamespace[$targetNamespace])) { + continue; + } + $xmlNamespace = $groupedByNamespace[$targetNamespace][0]['xmlNamespace']; + + assertType('string', $xmlNamespace); + assertType('non-empty-list&hasOffsetValue(1, string)', $mergedNamespace); + + $xsdFiles[$xmlNamespace] = []; + foreach ($mergedNamespace as $namespace) { + foreach ($groupedByNamespace[$namespace] ?? [] as $viewHelper) { + assertType('string', $viewHelper['name']); + $xsdFiles[$xmlNamespace][$viewHelper['name']] = $viewHelper; + } + } + // After assigning with string keys ($viewHelper['name']), $xsdFiles[$xmlNamespace] should NOT be a list + assertType('array|string, array{xmlNamespace: string, namespace: string, name: string}>', $xsdFiles[$xmlNamespace]); + $xsdFiles[$xmlNamespace] = array_values($xsdFiles[$xmlNamespace]); + } +}