Skip to content

Add non regression test for 9401 #4136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int<1, max>> but returns list<int<0, max>>.',
17,
],
]);
}

}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-9401.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Bug9401;

/**
* @param array<mixed> $foos
* @return list<positive-int>
*/
function foo(array $foos): array
{
$list = [];
foreach ($foos as $foo) {
if (is_int($foo) && $foo >= 0) {
$list[] = $foo;
}
}
return $list;
}
Loading