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

try-finally false positive #2969

Closed
Firtzberg opened this issue Feb 10, 2020 · 6 comments
Closed

try-finally false positive #2969

Firtzberg opened this issue Feb 10, 2020 · 6 comments

Comments

@Firtzberg
Copy link

Firtzberg commented Feb 10, 2020

Bug report

I have a try finally block. I want to make sure resources are cleaned up no matter what. I use a simple flag to keep track if the resource was consumed.

Code snippet that reproduces the problem

https://phpstan.org/r/d716d2ac-adc4-4f4a-bdc7-2576859f90ee

Expected output

The static analysis should not claim that the boolean expression at line 22 is always false.

@ondrejmirtes
Copy link
Member

Thanks. Right now you can work around it like this: https://phpstan.org/r/da18cec8-7577-4d42-b03b-8697da96438e

@e1himself
Copy link

e1himself commented Mar 19, 2021

I have the same issue in my code.

https://phpstan.org/r/bc3e6e26-dae9-4909-ba42-653c57618def

@phpstan-bot
Copy link
Contributor

@Firtzberg After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-22: Negated boolean expression is always false.
+No errors

@phpstan-bot
Copy link
Contributor

@e1himself After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-16: Variable $success in isset() always exists and is not nullable.
+No errors

@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src#481

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants