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

UndefinedDocblockClass for generic template #2697

Closed
simPod opened this issue Jan 26, 2020 · 7 comments
Closed

UndefinedDocblockClass for generic template #2697

simPod opened this issue Jan 26, 2020 · 7 comments

Comments

@simPod
Copy link
Contributor

simPod commented Jan 26, 2020

I'm getting

UndefinedDocblockClass - 9:23 - Docblock-defined class or interface O does not exist

<?php
 
class Output {
}

/** @template O of Output */
interface Format
{
    /** @psalm-return O */
    public static function output(string $contents) : Output;
}

This works just fine with phpstan. I went through docs and some internal stubs here and can't see what I'm doing wrong. Why psalm does not know O for @return when it's defined as a template? Thanks!

@vimeo vimeo deleted a comment from psalm-github-bot bot Jan 26, 2020
@muglug
Copy link
Collaborator

muglug commented Jan 26, 2020

@simPod I removed the ability to use templated classes in static methods because it's easy to get things wrong – I created a feature request in PHPStan's repo here: phpstan/phpstan#2738, and here's a link to where I announced I was mentioned that I was breaking this feature in Psalm: phpstan/phpstan#2731 (comment)

@muglug muglug closed this as completed Jan 26, 2020
@simPod
Copy link
Contributor Author

simPod commented Jan 27, 2020

Thanks for links! Can you briefly explain what does it's easy to get things wrong mean? I read those discussions and snippets but it's hard to spot the problem. Is it about methods not being pure? Thanks a lot.

@muglug
Copy link
Collaborator

muglug commented Jan 27, 2020

No, it's about thinking that you have some sort of templated protections & inference on input, when in fact you don't. The author was intending for $a to be templated as Some<string> here: https://phpstan.org/r/16a98fd4-f85f-421d-bb21-cb4da6d08694

@simPod
Copy link
Contributor Author

simPod commented Jan 28, 2020

I see the issue but isn't there the same problem with calling it through dynamic context? https://phpstan.org/r/da30f478-a9fe-4e67-972d-351e1965b531
I kinda expect PHP not to give me any guarantees based on phpdocs :D

@simPod
Copy link
Contributor Author

simPod commented Mar 3, 2020

@muglug if you had a few seconds I'd be very curious on your view here. It doesn't "click" together to me now :( Thanks!

@muglug
Copy link
Collaborator

muglug commented Mar 4, 2020

I think your example should now work in Psalm - after further consideration I reverted to the more-permissive behaviour.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/56eabbc3e2
<?php
 
class Output {
}

/** @template O of Output */
interface Format
{
    /** @psalm-return O */
    public static function output(string $contents) : Output;
}
Psalm output (using commit 0f5b0fd):

No issues!

kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Jan 23, 2024
Psalm does not support class @template in static methods.
And in PHPStan it does not protect.
See
- vimeo/psalm#2697
- phpstan/phpstan#2738
kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Jan 23, 2024
Psalm does not support class @template in static methods.
And in PHPStan it does not protect.
See
- vimeo/psalm#2697
- phpstan/phpstan#2738
kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Jan 23, 2024
Psalm does not support class @template in static methods.
And in PHPStan it does not protect.
See
- vimeo/psalm#2697
- phpstan/phpstan#2738
kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Jan 23, 2024
Psalm does not support class @template in static methods.
And in PHPStan it does not protect.
See
- vimeo/psalm#2697
- phpstan/phpstan#2738
kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Jan 23, 2024
Psalm does not support class @template in static methods.
And in PHPStan it does not protect.
See
- vimeo/psalm#2697
- phpstan/phpstan#2738
kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Jan 23, 2024
Psalm does not support class @template in static methods.
And in PHPStan it does not protect.
See
- vimeo/psalm#2697
- phpstan/phpstan#2738
kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Jan 23, 2024
Psalm does not support class @template in static methods.
And in PHPStan it does not protect.
See
- vimeo/psalm#2697
- phpstan/phpstan#2738
kenjis added a commit to kenjis/CodeIgniter4 that referenced this issue Jan 29, 2024
Psalm does not support class @template in static methods.
And in PHPStan it does not protect.
See
- vimeo/psalm#2697
- phpstan/phpstan#2738
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