diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index 38d1e6741b..b6a16d4c18 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -290,6 +290,10 @@ public function isList(): TrinaryLogic return TrinaryLogic::createNo(); } + if ($this->getKeyType()->isSuperTypeOf(new ConstantIntegerType(0))->no()) { + return TrinaryLogic::createNo(); + } + return TrinaryLogic::createMaybe(); } diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index 726542e93d..2e6b5c084d 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -3262,6 +3262,22 @@ public function testBug9009(): void $this->analyse([__DIR__ . '/data/bug-9009.php'], []); } + public function testBug9487(): void + { + $this->checkThisOnly = false; + $this->checkNullables = false; + $this->checkUnionTypes = false; + $this->checkExplicitMixed = false; + + $this->analyse([__DIR__ . '/data/bug-9487.php'], [ + [ + 'Parameter #1 $x of method Bug9487\HelloWorld::sayHello() expects list, array, string> given.', + 15, + 'array, string> is not a list.', + ], + ]); + } + public function testBuSplObjectStorageRemove(): void { $this->checkThisOnly = false; diff --git a/tests/PHPStan/Rules/Methods/data/bug-9487.php b/tests/PHPStan/Rules/Methods/data/bug-9487.php new file mode 100644 index 0000000000..6bcf34c49d --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-9487.php @@ -0,0 +1,17 @@ + $x */ + public function sayHello($x): void + { + } + + /** @param array $x */ + public function invoke($x): void + { + $this->sayHello($x); + } +}