-
-
Notifications
You must be signed in to change notification settings - Fork 861
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
Keeps forgetting about @var doc comments #5921
Comments
This bug report is missing a link to reproduction on phpstan.org. It will most likely be closed after manual review. |
Would be great if you could test it with phpstan-src and bisect it to a specific commit where it starts happening. |
This is gonna take ages then, because it doesn't happen all the time :/ |
I saw the same problem while I updated from 0.12.99 to 1.0.0, but after I fixed my extensions / config etc. it disappeared. Can you show your current phpstan config? |
I and some colleagues of mine also see this. Our projects are proprietary so I cannot share any detailed info but maybe the following helps:
One case where the issue appeared for me is like this:
(I included the method PHPDoc in case that's relevant; I guess/hope it's not because it should be redundant.) |
@InvisibleSmiley could you put that code into a repo in which the error can be reproduced? |
I don't know how to reproduce it. All I'm saying is that the issue appeared in code similar to the example. No idea what's needed to trigger the issue. Hence no point in creating a repo for it at this stage. |
FWIW, the common theme always seems to be inline @var. I'm waiting for the issue to recur so I can attempt to compare caches and see what caused it, but no luck so far. |
I just got a hit, but comparing caches seems like needle in a haystack: $ git diff --shortstat --no-index ~/AppData/Local/Temp/phpstan-broken/ ~/AppData/Local/Temp/phpstan
38979 files changed, 1414 insertions(+), 5200237 deletions(-) I hope someone knows a better way to reproduce this, because I got nothing. Best I have is that it seems to recur when modifying a file that contains inline |
I have the same problem, code that produces this is something like this: "Solution"
As I get hundreds of those errors, renaming variables can't be a solution, so I keep clearing the cache, but that also is not great as it rescans all files on the next run. |
@dktapps |
PhpStorm analyses files copied to ~/AppData/Local/Temp/PHPStantemp_folder%d, so cache won't hit on such cases since the real file path is different. That's also the reason why file-specific ignoreErrors don't work in PhpStorm. |
Ok, didn't know that, thanks for pointing it out, that explains the strange behavior :) |
I have done some more research on this, still can't reproduce it, but found something that may be related. What struck me was that I have two folders with cached phpstan-results:
I created an error that gets reported in phpstan, ran phpstan and rector afterwards and was thinking that due to the second cache-directory maybe the error was transferred to the rector-cache which was now used by phpstan so the error seemingly would never disappear (as "clear-result-cache" only clears the directories created by phpstan but not the ones created by rector). Unfortunately, that did not happen, both phpstan and rector report no errors after fixing the one created for the test - which of course is the expected behavior. (Also tried the other way around: delete all caches, create error, run rector, remove error, run phpstan - same result: everything ok, no false positives.) As I said, I'm still not able to produce the error on purpose, I just thought I'd share my findings in case it puts somebody on the right track. |
Interesting, could phpstan runs from other local projects influence the cache there somehow? I think phpstan would just re-create it then but would be interesting if this also occurs if a local cache is used, see #4237 (comment) |
There are no other local projects that run phpstan, but: PhpStorm! I usually run phpstan via the console to get a full list of warnings apart from the "live"-warnings I get in PhpStorm. But from time to time I run the code inspection in PhpStorm on the whole project and that seems to cause the problem. While I did a lot of testing (see my last post) and couldn't reproduce it, right after running PhpStorm's code inspection of my project, it came up with a new list of false positives that now show in phpstan even if run via the console! Also strange: In PhpStorm's problem result window, I got 108 warnings from phpstan, but only a handful are actual warnings, all other are: "phpstan: PHPStan crashed in the previous run probably because of excessive memory consumption. |
If PhpStorm violates the takeaway from this article https://phpstan.org/blog/why-you-should-always-analyse-whole-project then sure, I know the reason why this is happening. This is because of an optimization I did for PHPStan 1.0. Before AST is cached and if it's not in the analysed paths, the function bodies are removed because they're irrelevant for PHPStan. This makes sense for vendor directory. What's probably happening in this case is that PHPStan just runs on a single file and the rest is considered 3rd party and therefore the I see two possible solutions:
|
AFAIK the logic for pre-1.0 was that single file analysis results were not cached at all. Why not stick to that simple principle? (I don't really care either way as long as this gets fixed somehow, just wondering.) |
@InvisibleSmiley It's not about result cache, it's about PHPDocs cache. |
Yes it does. It analyzes only the currently editing file by copying it to tmpdir. |
Correct: "The problem occurs since we copy files to the temporary folder so the file path becomes /tmp/foobar/<location_of_file> and we use a working dir of the project." - |
The more I run into this the more I'm certain that the PhpStorm hypothesis is correct. I ran into this dozens of times yesterday while updating an old project. The whole time I was switching between PhpStorm, and CLI to run PHPStan, and then back again. |
See https://youtrack.jetbrains.com/issue/WI-63918 for a similar problem, related to single-file analysis |
Yeah, but running analysis on single files shouldn't break PHPStan this way, regardless of what JetBrains decides to do. |
I've been running into this recently as well. An interesting observation that may or may not be relevant is that running |
Should be fixed: phpstan/phpstan-src@2652f2d Please test dev-master to confirm the fix. Thanks. |
Did a testrun with phpstan then PhpStorm project code inspection then phpstan, no false positives any more, looking good to me! |
|
@ondrejmirtes please reopen this, it's still occurring (just ran into it again now, everything is definitely updated this time). |
Please open a new issue and specify where it's happening exactly. Try to provide the exact steps to reproduce. |
It's like before, I have no idea what triggers it and it doesn't happen in the same place each time. Sometimes I can go for a day or two without seeing it. |
Same here, PHPStan 1.2.0 and I still see such errors 1-2 times per day. I'm simply manually deleting the tmp files, and then it's working again. I have added a different phpstan-config for the integration in phpstorm (with a different |
Hi, @ondrejmirtes the remaining false-positives I get are all coming from places where |
@dktapps Makes sense given the fix: phpstan/phpstan-src@2652f2d Feel free to send a PR for prefixed tags. |
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. |
Bug report
I'm not sure exactly what triggers this. Hopefully someone reading this issue does.
I hate that this is one of those "it randomly happens" issues, but unfortunately this is the best I got right now.
Note that deleting PHPStan's cache in
$TEMP/phpstan
resolves the issue.Summary
Analysing latest PM, PHPStan randomly forgets @var doc comments like these:
https://github.com/pmmp/PocketMine-MP/blob/c77829f4adee4d5fe61829823f4dbad545c100e9/src/entity/Human.php#L254
https://github.com/pmmp/PocketMine-MP/blob/b9b1ba95261f90e61657a0220ca8a59fa0dad9d7/src/entity/Living.php#L153
https://github.com/pmmp/PocketMine-MP/blob/3be9548b1ea240cdf352fa08a603cc3729f88682/src/network/mcpe/compression/CompressBatchTask.php#L48
https://github.com/pmmp/PocketMine-MP/blob/bb05af103d22148dbe3aa053a2119c2603282343/src/plugin/PluginManager.php#L497
https://github.com/pmmp/PocketMine-MP/blob/f827a555d5f98f22aea919f165853dff224b5176/src/utils/Utils.php#L178
which spontaneously leads to bogus errors like these:
Deleting PHPStan's cache
$TEMP/phpstan
resolves the issue, but it keeps recurring.Code snippet that reproduces the problem
Linked above, but like I said, it doesn't happen all the time.
Expected output
The above errors shouldn't be reported (they are bogus).
The text was updated successfully, but these errors were encountered: