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

False positive with when using in_array with literals (or constants) #668

Closed
wants to merge 3 commits into from

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 11, 2021

@staabm staabm changed the title added failling test False positive with when using in_array with literals (or constants) Sep 11, 2021
@@ -103,6 +104,10 @@ public function findSpecifiedType(
return null;
}

if ($needleType instanceof ConstantType && !$haystackType instanceof ConstantArrayType) {
Copy link
Contributor Author

@staabm staabm Sep 11, 2021

Choose a reason for hiding this comment

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

I tried different approaches on how to fix the added failling tests.

no matter which one I implement, some tests start failling.
The PR as is fixed the newly added cases but regresses existing tests.

I need to sleep over it. any hints welcome

Copy link
Member

Choose a reason for hiding this comment

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

Yes, in_array is a mad beast. It might need a complete rethinking of this approach.

This is also an opportunity to fix https://github.com/phpstan/phpstan/issues/5355 - it means that these conditions should not be in ImpossibleCheckTypeHelper, but in InArrayFunctionTypeSpecifyingExtension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants