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

Assignment of empty SplObjectStorage #4055

Closed
enumag opened this issue Aug 25, 2020 · 3 comments
Closed

Assignment of empty SplObjectStorage #4055

enumag opened this issue Aug 25, 2020 · 3 comments
Labels

Comments

@enumag
Copy link
Contributor

enumag commented Aug 25, 2020

There seems to be some issue with SplObjectStorage - I can't assign empty SplObjectStorage to an annotated property. Note that this works just fine for other generic types since b26deb4.

https://psalm.dev/r/747947d7b6

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/747947d7b6
<?php declare(strict_types = 1);

class HelloWorld
{
    /**
	 * @var SplObjectStorage<DateTimeImmutable, null>
	 */
	public SplObjectStorage $dates;
	
	public function __construct()
	{
		$this->dates = new SplObjectStorage();
	}
}
Psalm output (using commit 7dba9bc):

ERROR: PropertyTypeCoercion - 12:18 - $this->dates expects 'SplObjectStorage<DateTimeImmutable, null>',  parent type 'SplObjectStorage<object, mixed>' provided

@muglug
Copy link
Collaborator

muglug commented Aug 25, 2020

It's because the constructor doesn't take templated params, so there's nothing to be considered empty. I think the only way around this is to hack things a bit.

@ondrejmirtes
Copy link

I think it's sufficient to add the constructor with type variable parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants