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
array_filter callback throwing exception not reflected by phpstan, giving error about useless throws annotation #5001
Comments
I have another example: #5043 You flag this as easy fixes @ondrejmirtes, any recommendation about how to fix it ? :) |
This needs a dynamic throw type extension for those functions that execute callbacks immediately. The extension needs to look like this: #4819 (comment) |
With something like this https://github.com/phpstan/phpstan-src/blob/master/src/Type/Php/JsonThrowTypeExtension.php#L22-L25, I assume ? So we have to list all the php function which take a callback and use it immediately, there is a lot I think. |
Yeah, configurable like that. I think we can only cover the most common ones. Throwing an exception from callbacks like that isn't a good reason anyway and you should be using foreach, that's why I think it's an edgecase. |
@janedbal After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-No errors
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #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
|
@janedbal After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-No errors
+10: Method HelloWorld::filter() should return array<string> but return statement is missing. Full report
|
This change is very tricky, every closure is now a black hole ending the exception chain without any check. |
Whole this issue is solved in forbidCheckedExceptionInCallable which even allows you setup more methods/functions that are immediatelly called (like |
Thank you for that. |
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. |
Addressed by phpstan/phpstan-src@74c02de. |
Bug report
Following snippet gives following error when using new tooWideThrowType check
Code snippet that reproduces the problem
https://phpstan.org/r/df0c05f1-1f50-4361-bca3-e261fd5db47e
Expected output
No error
The text was updated successfully, but these errors were encountered: