diff --git a/src/PhpDoc/TypeNodeResolver.php b/src/PhpDoc/TypeNodeResolver.php index 78e0ad68fa..10c701a90a 100644 --- a/src/PhpDoc/TypeNodeResolver.php +++ b/src/PhpDoc/TypeNodeResolver.php @@ -429,7 +429,7 @@ private function resolveIntersectionTypeNode(IntersectionTypeNode $typeNode, Nam private function resolveArrayTypeNode(ArrayTypeNode $typeNode, NameScope $nameScope): Type { $itemType = $this->resolve($typeNode->type, $nameScope); - return new ArrayType(new MixedType(), $itemType); + return new ArrayType(new BenevolentUnionType([new IntegerType(), new StringType()]), $itemType); } private function resolveGenericTypeNode(GenericTypeNode $typeNode, NameScope $nameScope): Type @@ -439,7 +439,7 @@ private function resolveGenericTypeNode(GenericTypeNode $typeNode, NameScope $na if ($mainTypeName === 'array' || $mainTypeName === 'non-empty-array') { if (count($genericTypes) === 1) { // array - $arrayType = new ArrayType(new MixedType(true), $genericTypes[0]); + $arrayType = new ArrayType(new BenevolentUnionType([new IntegerType(), new StringType()]), $genericTypes[0]); } elseif (count($genericTypes) === 2) { // array $keyType = TypeCombinator::intersect($genericTypes[0], new UnionType([ new IntegerType(), diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 04b005e767..ad590cb524 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -870,4 +870,10 @@ public function testBug2782(): void ]); } + public function testBug5661(): void + { + $this->checkExplicitMixed = true; + $this->analyse([__DIR__ . '/data/bug-5661.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/bug-5661.php b/tests/PHPStan/Rules/Functions/data/bug-5661.php new file mode 100644 index 0000000000..471594e367 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-5661.php @@ -0,0 +1,24 @@ + $array + */ + function sayHello(array $array): void + { + echo join(', ', $array) . PHP_EOL; + } + + /** + * @param string[] $array + */ + function sayHello2(array $array): void + { + echo join(', ', $array) . PHP_EOL; + } + +}