Skip to content
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

Fix always-true detection in in_array with union type haystack #3888

Open
wants to merge 3 commits into
base: 2.1.x
Choose a base branch
from

Conversation

sayuprc
Copy link
Contributor

@sayuprc sayuprc commented Mar 19, 2025

@staabm
Copy link
Contributor

staabm commented Mar 19, 2025

your PR has impact on more open bugs.

please look at the changes and decide whether these are correct/intended
https://github.com/phpstan/phpstan-src/actions/runs/13947226248?pr=3888

please add additional tests to cover this bugs, in case they are fixed

Comment on lines +22 to +34
/**
* @param array{
* key1: ?bool,
* } $myArray
*/
public function testBool(array $myArray): ?\stdClass
{
if (\in_array(null, $myArray, true)) {
return null;
}

return (object) $myArray;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should test a case which is expected to still emit an error after the change (a array which always contains null)

@sayuprc sayuprc requested a review from staabm March 21, 2025 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect NarrowedType detection on in_array(null) and bool value
2 participants