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

\WeakReference template gets confused when using $this #7508

Closed
jack-worman opened this issue Jan 28, 2022 · 4 comments
Closed

\WeakReference template gets confused when using $this #7508

jack-worman opened this issue Jan 28, 2022 · 4 comments

Comments

@jack-worman
Copy link
Contributor

https://psalm.dev/r/0e0fe7d714

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/0e0fe7d714
<?php

class Foo {
    /**
     * @return WeakReference<Foo>
     */
    public function bar(): WeakReference
    {
		return \WeakReference::create($this);
    }
    
    /**
     * @return WeakReference<Foo>
     */
    public function baz(): WeakReference
    {
		return \WeakReference::create(new Foo());
    }
}
Psalm output (using commit 4609bc4):

ERROR: InvalidReturnStatement - 9:10 - The inferred type 'WeakReference<WeakReference>' does not match the declared return type 'WeakReference<Foo>' for Foo::bar

ERROR: InvalidReturnType - 5:16 - The declared return type 'WeakReference<Foo>' for Foo::bar is incorrect, got 'WeakReference<WeakReference>'

@weirdan
Copy link
Collaborator

weirdan commented Jan 28, 2022

It appears the problem lies in the interpretation of Foo&static, as everything works as expected in a final method.

@orklah orklah added the static label Jan 28, 2022
@weirdan
Copy link
Collaborator

weirdan commented Nov 22, 2022

Can't reproduce anymore: https://psalm.dev/r/0e0fe7d714

@weirdan weirdan closed this as completed Nov 22, 2022
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/0e0fe7d714
<?php

class Foo {
    /**
     * @return WeakReference<Foo>
     */
    public function bar(): WeakReference
    {
		return \WeakReference::create($this);
    }
    
    /**
     * @return WeakReference<Foo>
     */
    public function baz(): WeakReference
    {
		return \WeakReference::create(new Foo());
    }
}
Psalm output (using commit 7869cb5):

No issues!

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

No branches or pull requests

3 participants