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

Static function return type loses template in traits #7682

Open
SCIF opened this issue Feb 16, 2022 · 2 comments
Open

Static function return type loses template in traits #7682

SCIF opened this issue Feb 16, 2022 · 2 comments

Comments

@SCIF
Copy link
Contributor

SCIF commented Feb 16, 2022

Version I found this behaviour: 4.20

https://psalm.dev/r/d68f60cae1

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/d68f60cae1
<?php

/** @template T */
trait B {
    /** @return array<T> */
    public function all() {return [];}
    
    /** @return array<T> */
    public static function statAll() {return [];}
}

class A {
    /** @use B<A> */
    use B;
}

$var = (new A)->all();
/** @psalm-trace $var */;

$var2 = A::statAll();
/** @psalm-trace $var2 */;
Psalm output (using commit 6af3b50):

INFO: Trace - 18:25 - $var: array<array-key, A>

INFO: Trace - 21:26 - $var2: array<array-key, never>

INFO: UnusedVariable - 17:1 - $var is never referenced or the value is not used

INFO: UnusedVariable - 20:1 - $var2 is never referenced or the value is not used

@orklah orklah added the traits label Feb 16, 2022
@AndrolGenhald
Copy link
Collaborator

Same root problem as #5753, static functions currently don't allow templates. Maybe we should add an InvalidDocblock error when it's attempted until we actually support it?

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