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

Property (iterable<T>|null) does not accept iterable<T> #6230

Closed
sanmai opened this issue Dec 22, 2021 · 5 comments
Closed

Property (iterable<T>|null) does not accept iterable<T> #6230

sanmai opened this issue Dec 22, 2021 · 5 comments
Labels
Milestone

Comments

@sanmai
Copy link
Contributor

sanmai commented Dec 22, 2021

Bug report

I'm looking at the following errors which read like nonsense:

  • Property Example<T>::$input (iterable<T>|null) does not accept iterable<T>.
  • Method Example::get() should return iterable<T>|null but returns iterable<T>|null.

Code snippet that reproduces the problem

https://phpstan.org/r/91bc6557-e814-4b06-bc9d-eb9d9ce17342

/**
 * @template T
 */
class Example
{
    /**
     * @var ?iterable<T>
     */
    private $input;
 
    /**
     * @param iterable<T> $input
     */
    public function __construct(iterable $input)
    {
        $this->input = $input;
    }
	
    /** @return ?iterable<T> */
    public function get(): ?iterable
    {
        return $this->input;	
    }
}

Expected output

No errors.

This new issue appeared when upgrading from 0.12.99 to 1.0.2.

@ondrejmirtes ondrejmirtes added this to the Generics milestone Dec 22, 2021
@arnaud-lb
Copy link
Contributor

Smaller snippet: https://phpstan.org/r/eafd4309-56cf-4698-b30f-d4cf578f2ad9

Problem disappears when specifying the iterable key to a non-mixed type: https://phpstan.org/r/f2035689-6518-4053-a57a-fe58256d25f9

Seems related to #6418

Probable cause:

@phpstan-bot
Copy link
Contributor

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

@@ @@
-19: Property Example<T>::$input (iterable<T>|null) does not accept iterable<T>.
-25: Method Example::get() should return iterable<T>|null but returns iterable<T>|null.
+No errors

@phpstan-bot
Copy link
Contributor

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

@@ @@
-9: Function test() should return iterable|null but returns iterable|null.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@9f12f0f

@github-actions
Copy link

github-actions bot commented Mar 6, 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 Mar 6, 2022
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

4 participants