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

Wrong type with static #7507

Closed
ddebin opened this issue Jan 28, 2022 · 3 comments
Closed

Wrong type with static #7507

ddebin opened this issue Jan 28, 2022 · 3 comments

Comments

@ddebin
Copy link

ddebin commented Jan 28, 2022

Wrong type resolution when class property is defined as static.

https://psalm.dev/r/f5f3b15557

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/f5f3b15557
<?php
/**
 * @template T
 */
class Foo
{
    /**
     * @var T[]
     */
    protected array $A = [];

    /**
     * @var T[]
     */
    protected static array $B = [];
}
Psalm output (using commit b9d9a49):

ERROR: UndefinedDocblockClass - 15:22 - Docblock-defined class, interface or enum named T does not exist

@orklah
Copy link
Collaborator

orklah commented Jan 28, 2022

This is on purpose. Psalm made a design choice that class-level templates and static properties/method should not mix.

@orklah orklah closed this as completed Jan 28, 2022
@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Jan 28, 2022

Related to #5753 and #7482. Class templates are currently ignored on static properties and methods. I think there are some cases where this should be allowed for methods, but it could cause harder problems if allowed on properties: https://3v4l.org/ZcQMS. We'll have to think over it carefully if we decide to support it in the future.

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

3 participants