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

Incorrect type with SplObjectStorage and generics when assigning to property with union type #4680

Closed
TRowbotham opened this issue Mar 10, 2021 · 7 comments

Comments

@TRowbotham
Copy link
Contributor

TRowbotham commented Mar 10, 2021

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 base SplObjectStorage<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.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Mar 10, 2021

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

@phpstan-bot
Copy link

phpstan-bot commented Sep 17, 2021

@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
Line Error
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>

@phpstan-bot
Copy link

phpstan-bot commented Sep 17, 2021

@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
Line Error
6 Property HelloWorld::$collection1 is never read, only written.
9 Property HelloWorld::$collection2 is never read, only written.

@phpstan-bot
Copy link

phpstan-bot commented Sep 17, 2021

@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
Line Error
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>

@phpstan-bot
Copy link

phpstan-bot commented Sep 17, 2021

@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
Line Error
6 Property HelloWorld::$collection1 is never read, only written.
9 Property HelloWorld::$collection2 is never read, only written.

@phpstan-bot
Copy link

phpstan-bot commented Sep 21, 2022

@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
Line Error
6 Property HelloWorld::$collection1 is never read, only written.
9 Property HelloWorld::$collection2 is never read, only written.

@github-actions
Copy link

github-actions bot commented Oct 24, 2022

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 Oct 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants