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

Psalm is sometimes inferring the wrong type for no reason. #4868

Closed
VincentLanglet opened this issue Dec 19, 2020 · 3 comments
Closed

Psalm is sometimes inferring the wrong type for no reason. #4868

VincentLanglet opened this issue Dec 19, 2020 · 3 comments

Comments

@VincentLanglet
Copy link
Contributor

Hi @muglug

I didn't succeed reproducing the issue in psalm.dev. But I have an open PR with commits about the issue:
sonata-project/SonataAdminBundle#6713

In this PR:

public function getNewInstance()
{
    $object = $this->getModelManager()->getModelInstance($this->getClass());

    $this->appendParentObject($object);

    foreach ($this->getExtensions() as $extension) {
        $extension->alterNewInstance($this, $object);
    }

    return $object;
}

Is reported as returning an object instead of the template T.

I find out that commenting

$this->appendParentObject($object);

fix the issue.

Then I find out that changing

/**
 * @phpstan-param T $object
 */
final protected function appendParentObject(object $object): void

to

/**
 * @phpstan-param T $object
 */
final protected function appendParentObject($object): void

fix the issue.

I think that psalm shouldn't report anything.
What is more weird, is that it's reporting an issue in the commit
sonata-project/SonataAdminBundle@1c08c17
but not in the previous commit
sonata-project/SonataAdminBundle@3091807

VincentLanglet added a commit to VincentLanglet/SonataAdminBundle that referenced this issue Dec 20, 2020
VincentLanglet added a commit to VincentLanglet/SonataAdminBundle that referenced this issue Dec 20, 2020
@muglug
Copy link
Collaborator

muglug commented Dec 21, 2020

Is this still the case on latest master?

@VincentLanglet
Copy link
Contributor Author

@VincentLanglet
Copy link
Contributor Author

The issue was on me.

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

No branches or pull requests

2 participants