-
Notifications
You must be signed in to change notification settings - Fork 545
Do not report dead catch with treatPhpDocTypesAsCertain: false
#4426
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
Do not report dead catch with treatPhpDocTypesAsCertain: false
#4426
Conversation
3b04c65 to
46dcb10
Compare
|
Damned, seems like an implicit throwPoint has impact on variable certainty... But maybe that's an ok change when looking at the existing behavior The variable certainly will be Maybe only in the try part and only with treatPhpDocTypesAsCertain: false I'll need your thought on this @ondrejmirtes |
Also, this would be the behavior you're asking for BackedEnumFromDynamicStaticMethodThrowTypeExtension |
|
The way it'd make sense for this to be implemented is:
I think all this means that explicit throw points (objects of ThrowPoint class) need to carry whether they're PHPDoc-based or not. |
|
With |
Isn't this a separate (big) next step after this draft ? We could
Looking at phpstan-src/src/Analyser/MutatingScope.php Line 6246 in 844f569
I feel like to have the exact same behavior, I should just change to |
|
My proposition is in line of what |
Maybe it's because I don't know enough this part of the codebase but this seems to me to be a too big work just to move forward the PR #4156 which seems to get unfortunately randomly blocked by a request change that every other DynamicThrowTypeExtension didn't got 😢 So I feel like I just have to add the DynamicThrowTypeExtension on my side rather than on PHPStan one |
|
I don't think it's too much complicated work. You need to look at every Alright, changing the handling of TryCatch in NodeScopeResolver might be necessary and that's 200 lines of code that you'd need to get into but still it's not rocket (or typesystem) science: phpstan-src/src/Analyser/NodeScopeResolver.php Lines 1678 to 1895 in 844f569
|
I'd like to move #4156 forward, and kinda disagree with your request change from calling
getTypetogetNativeTypeinsideBackedEnumFromDynamicStaticMethodThrowTypeExtension.Because when using the exception analysis, PHPStan will still ask for a
@throwstag while I know there is not because I trust my phpdoc (value-of<...>).Also, when looking at all the existing
DynamicMethodThrowTypeExtensionthey are usinggetType.So I tried to find a solution you will agree with.
-> If I trust the phpdoc, I consider it doesn't throw an exception.
-> If I don't, I check the throw type extension with the native type
--> If I don't have an exception with the native type I can still return NULL
--> If I have one, I had an implicit ThrowPoint.
The benefit of the implicit throwpoint is that:
@throwstag on the methodwhich is a similar behavior of
treatPhpDocTypesAsCertain: falsewhich allow extra safety check but doesn't enforce them.I didn't know how to correctly write test about this but the current one I wrote/updated should show the new behavior.