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

Caching of method result results in false positives #3203

Closed
marcelthole opened this issue Apr 24, 2020 · 5 comments
Closed

Caching of method result results in false positives #3203

marcelthole opened this issue Apr 24, 2020 · 5 comments
Labels
Milestone

Comments

@marcelthole
Copy link
Contributor

Bug report

Hey,

it seems that the return type of a method is cached, even if the reference of the object has changed in a other service. Therefore a method can be called twice and the return type could be changed by a other service

Code snippet that reproduces the problem

This works fine:
https://phpstan.org/r/d7904a4a-44a6-4bb2-a889-cc1dde0732c7
This produce an error:
https://phpstan.org/r/63d35fc8-acbd-4809-b4fb-c1c3556b6f85

Expected output

I expect, that any change of a object results in a new check of the method return values

@ondrejmirtes
Copy link
Member

To reword this bug report - when an object is passed somewhere, it should invalidate all it remembers about it in the current scope: (new PersistingService())->persist($sut);

@phpstan-bot
Copy link
Contributor

@marcelthole PHPStan now reports different result with your code snippet:

@@ @@
+32: Call to function assert() with false will always evaluate to false.
 32: Strict comparison using !== between null and null will always evaluate to false.
Full report
Line Error
32 Strict comparison using !== between null and null will always evaluate to false.
32 Strict comparison using !== between null and null will always evaluate to false.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-32: Strict comparison using !== between null and null will always evaluate to false.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@f92b95e

@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

3 participants