-
-
Notifications
You must be signed in to change notification settings - Fork 863
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
Incorrect variable always exists #778
Comments
Similar to #505. |
Hi, do you have some other example besides finally block?
On Sat, 20 Jan 2018 at 21:43, Michael Moravec ***@***.***> wrote:
Similar to #505 <#505>.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#778 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGZuObLopSt_ePn7ZoXFkbv5qZ1aU3oks5tMk_5gaJpZM4Rlk8R>
.
--
Ondřej Mirtes
|
I don't. However, the issue is not limited for the case when isset is inside finally block. See https://phpstan.org/r/e387cd1084ac70eb3ec94099c9e7b060. EDIT Well now that I think about it, that isset is actually unreachable, so maybe not the same issue. |
I'm gonna leave this open because of the second example, it will require some advanced exception tracking which is not yet possible. |
@ondrejmirtes I have another example, this time without exceptions entirely: https://phpstan.org/r/f28dcad21970df5f00f71201c1123320 Interesting fact, if you remove the |
@lookyman Please submit this as a new issue next time, this makes issue management harder 😊 I will look into it. |
Fixed: 0da95fc |
I solved the original issue: 7efd23c - basically all the variables in |
Hey @ondrejmirtes, when I run the code snippet again, it still reports the false negative. Is this a regression? |
Yes. |
I just run into this one, here is my use case https://phpstan.org/r/dbe44f1b-cb9d-4867-b266-61beb928fbaa |
@ondrejmirtes I'm trying to tackle this one, but I've gotten stuck. https://phpstan.org/r/dbe44f1b-cb9d-4867-b266-61beb928fbaa I was hoping I could check the type of |
@rainbow-alex That amount of precision is not that easy. We'd have to carry information in But this issue is marked as an easy fix - it might be fixable somewhere around the lines (https://github.com/phpstan/phpstan-src/blob/6bcb400f4540adaeaedf67a1929a6e601f69caa4/src/Analyser/NodeScopeResolver.php#L962-L1024), without the regard to what's on the right side of the variable assignment. Basically any variable assignment in |
There are definitely some variable assignments that are safe, though they are not very useful:
In review I would always argue for taking that assignment out of the try block, so I am not concerned about considering this a 'maybe' for analysis per se.
Here it gets tricky:
So yes, we could assign all variables as 'maybe' until the final
Thinking about it in depth, I think we can accurately model this by just splitting/merging scopes according to the semantics of try/catch/finally:
I think |
You can try to do it. You'll see which test cases will fail and we'll probably have to decide which behaviour is better/less annoying :) |
You can do it in spirit of NodeScopeResolverTest::testFileAsserts (the easiest way to test this) but currently there's only |
BTW I implemented |
@kunicmarko20 After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-15: Variable $file in isset() always exists and is not nullable.
+No errors |
Fixed by: phpstan/phpstan-src#481 |
Closes phpstan/phpstan#1597 Closes phpstan/phpstan#3617 Closes phpstan/phpstan#778 Closes phpstan/phpstan#2969 Closes phpstan/phpstan#3004 Closes phpstan/phpstan#3710 Closes phpstan/phpstan#3822 Closes phpstan/phpstan#505 Closes phpstan/phpstan#1670 Closes phpstan/phpstan#1219
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. |
Summary of a problem or a feature request
PHPStan incorrectly reports that a variable always exists in some cases.
Code snippet that reproduces the problem
https://phpstan.org/r/b0e37609338d0c49645295f039a0e73d
Expected output
PHPStan complains that
Variable $handle in isset() always exists and is not nullable.
. However, https://3v4l.org/nUfFW shows the actual output isko
, which means theisset
gets evaluated to false.The text was updated successfully, but these errors were encountered: