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 always-true with in_array
#5354
Comments
I guess needs fixing in https://github.com/phpstan/phpstan-src/blob/master/src/Type/Php/TypeSpecifyingFunctionsDynamicReturnTypeExtension.php or one of the helpers called from it |
hmm had a look into it. I don't know how to solve it, because
leads to $a typed with this also makes me question, whether phpstan/phpstan-src#606 is a good thing, I implemented earlier today |
Ideally all of this should be handled in InArrayFunctionTypeSpecifyingExtension. It would also fix phpstan/phpstan-webmozart-assert#142. |
The issue can be simplified to https://phpstan.org/r/02705e4a-3f03-4fa4-83c1-9e1ec86a76f5
|
@VincentLanglet After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-15: Call to function in_array() with arguments 0, array<int, 0|1> and true will always evaluate to true.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument phpstan/phpstan#2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md Full report
|
@VincentLanglet After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Call to function in_array() with arguments 0, array<int, 0|1> and true will always evaluate to true.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument phpstan/phpstan#2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md Full report
|
@VincentLanglet After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-15: Call to function in_array() with arguments 0, array<int, 0|1> and true will always evaluate to true.
+No errors |
@VincentLanglet After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Call to function in_array() with arguments 0, array<int, 0|1> and true will always evaluate to true.
+No errors |
Seems fixed |
1 similar comment
Seems fixed |
This was a bug in the playground, it's not fixed. |
@ondrejmirtes We're also dealing with this constant array union type issue (and the other false positive looks pretty dangerous). I'm not sure how to re-implement the rule in the context of InArrayFunctionTypeSpecifyingExtension. Can you give me a hint? I may try to look into it. |
@olsavmic You can ask Scope for the same information in InArrayFunctionTypeSpecifyingExtension the ImpossibleCheckTypeHelper asks right now. That would fix phpstan/phpstan-webmozart-assert#142 (because that scenario uses InArrayFunctionTypeSpecifyingExtension indirectly and avoids ImpossibleCheckTypeHelper). As for this specific issue, you need to come up with the logic that would fix it. |
Fixed: phpstan/phpstan-src@4321374 |
Closes phpstan/phpstan#5759 Closes phpstan/phpstan#5668 Closes phpstan/phpstan#5496 Closes phpstan/phpstan#4666 Closes phpstan/phpstan#3892 Closes phpstan/phpstan#3314 Closes phpstan/phpstan#2870 Closes phpstan/phpstan#5354
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I expect no error from the code
https://phpstan.org/r/179a9da2-e9e7-4d4b-b4af-b0e01c35a9db
In my project issue I get
But even if the array is non-empty, the in_array check isn't supposed to be always true.
The text was updated successfully, but these errors were encountered: