diff --git a/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php b/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php index 46e46d3db1..663f2ae211 100644 --- a/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php @@ -357,4 +357,17 @@ public function testBug12274(): void ]); } + public function testBug9401(): void + { + $this->checkExplicitMixed = true; + $this->checkNullables = true; + + $this->analyse([__DIR__ . '/data/bug-9401.php'], [ + [ + 'Function Bug9401\foo() should return list> but returns list>.', + 17, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/bug-9401.php b/tests/PHPStan/Rules/Functions/data/bug-9401.php new file mode 100644 index 0000000000..a818188f31 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-9401.php @@ -0,0 +1,18 @@ + $foos + * @return list + */ +function foo(array $foos): array +{ + $list = []; + foreach ($foos as $foo) { + if (is_int($foo) && $foo >= 0) { + $list[] = $foo; + } + } + return $list; +}