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
Hook callback false positives for mixed
return type
#130
Hook callback false positives for mixed
return type
#130
Conversation
also looking at this right now :) yeah, the problem is that a |
oh and btw another test case for implicit mixed is simply something like the following function return_value_mixed_implicit( $value ) {
return $value;
} if you put my false-positive was more dynamic, with a conditional inside, but it comes down to the same thing basically UPDATE: oh, CI is red already, nevermind then, the test cases are good enough! |
mixed
return type
Co-authored-by: Viktor Szépe <viktor@szepe.net>
Fyi using the following patch seems to greatly improve it already for me. But we can still not differentiate between no return at all and mixed implicit return. Type-wise it makes sense, since PHPStan is not looking at the function body but only the definition and unfortunately I don't know if there's another way of getting the info if there's a protected function validateFilterReturnType(ParametersAcceptor $callbackAcceptor): void
{
$returnType = $callbackAcceptor->getReturnType();
- $isVoidSuperType = $returnType->isSuperTypeOf(new VoidType());
- if (! $isVoidSuperType->yes()) {
+ if (
+ ($returnType instanceof MixedType && $returnType->isExplicitMixed())
+ || !$returnType->isSuperTypeOf(new VoidType())->yes()
+ ) {
return;
} Give me a sec, I'm gonna ask at phpstan if there's something else.. on second thought I think you did the right thing with using |
I think we got a bit distracted by implicit mixed, which isn't the responsibility of this library to figure out. If your callback uses implicit mixed then PHPStan flags the callback as having a missing return type (these tests are in place to ensure this library doesn't trigger an error in that situation). |
You paint CI feedback green, I'll merge it right away. |
good point. In that case - does it make sense to also use RuleLevelHelper then, as you do with add_action? Or turn the supertype check around like to report only for when something is surely a void return via |
Okay I removed the implicit mixed handling (which is how it should be), added support for explicit mixed handling, and CI is all green. |
Thank you! I hope every user will be happy. |
Nice, thank you! |
Fixes #125
Seems the problem is ultimately down to
mixed
return types.