From f82383e71dac600b993eac75b1a9808752b05535 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 20 Jul 2025 22:44:40 +0200 Subject: [PATCH] Add non regression test --- .../Rules/Functions/ReturnTypeRuleTest.php | 13 +++++++++++++ .../PHPStan/Rules/Functions/data/bug-9401.php | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/PHPStan/Rules/Functions/data/bug-9401.php 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; +}