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 type with SplObjectStorage and generics when assigning to property with union type #4680
Comments
Hi, I consider this a feature request as the second property works because of a convenient shortcut I implemented. Normally you'd have to do this: https://phpstan.org/r/5bd693a7-db72-4c45-ad17-6de5afb0c3a7 |
@TRowbotham After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
+ 6: Property HelloWorld::$collection1 is never read, only written.
+ 9: Property HelloWorld::$collection2 is never read, only written.
13: Property HelloWorld::$collection1 (SplObjectStorage<HelloWorld, null>|null) does not accept SplObjectStorage<object, mixed>. Full report
|
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-No errors
+6: Property HelloWorld::$collection1 is never read, only written.
+9: Property HelloWorld::$collection2 is never read, only written. Full report
|
@TRowbotham After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
+ 6: Property HelloWorld::$collection1 is never read, only written.
+ 9: Property HelloWorld::$collection2 is never read, only written.
13: Property HelloWorld::$collection1 (SplObjectStorage<HelloWorld, null>|null) does not accept SplObjectStorage<object, mixed>. Full report
|
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-No errors
+6: Property HelloWorld::$collection1 is never read, only written.
+9: Property HelloWorld::$collection2 is never read, only written. Full report
|
@TRowbotham After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
-13: Property HelloWorld::$collection1 (SplObjectStorage<HelloWorld, null>|null) does not accept SplObjectStorage<object, mixed>.
+ 6: Property HelloWorld::$collection1 is never read, only written.
+ 9: Property HelloWorld::$collection2 is never read, only written. Full report
|
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
Assigning
SplObjectStorage
to a property using generics with a union type makes phpstan think the type being assigned to the property is the baseSplObjectStorage<object, mixed>
type instead of the phpdoc type.Code snippet that reproduces the problem
https://phpstan.org/r/09935280-ccfb-417d-aeec-61b180e5d1c1
Expected output
There should be no error.
The text was updated successfully, but these errors were encountered: