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

Improve parameter type of SplObjectStorage::removeAll/Except #2892

Merged
merged 1 commit into from Mar 20, 2024

Conversation

schlndh
Copy link
Contributor

@schlndh schlndh commented Jan 28, 2024

See https://phpstan.org/r/bff03687-1f39-496b-a23e-0386bcb75362 . Ideally, removeNoIntersect should be reported as an issue since it is not possible for the removes to do anything. However, AFAIK there is no way to express such constraint in the current type system (i.e. I'd want to make sure that the key types of the two storages have a non-empty intersection).

I considered using \SplObjectStorage<covariant TObject, *>|\SplObjectStorage<contravariant TObject, *>, which would report removeNoIntersect, but it would lead to a false positive in removePossibleIntersect. And \SplObjectStorage<*, *> seems to have been the intention of the previous stub.

Fixes phpstan/phpstan#9411

@ondrejmirtes ondrejmirtes merged commit e8e466d into phpstan:1.10.x Mar 20, 2024
43 checks passed
@ondrejmirtes
Copy link
Member

Nice, thanks a lot!

@schlndh schlndh deleted the fix-SplObjectStorageRemove branch March 20, 2024 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants