vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.57k stars 660 forks source link

Support call-site variance syntax from PHPStan #10222

Open VincentLanglet opened 1 year ago

VincentLanglet commented 1 year ago

PHPStan introduced call-site variance https://phpstan.org/blog/guide-to-call-site-generic-variance But Psalm doesn't support the syntax so far. https://psalm.dev/r/8244015134

Would it be something possible ? A first step could be at least to not report an error for Foo<*> and consider Foo

Then there will be Foo<covariant Bar> and Foo<contravariant Bar>

psalm-github-bot[bot] commented 1 year ago

I found these snippets:

https://psalm.dev/r/8244015134 ```php $collection */ function printSize(Collection $collection): int { return $collection->count(); } ``` ``` Psalm output (using commit 7428e49): ERROR: InvalidDocblock - 11:12 - Invalid type '*' in docblock for printSize ```
kkmuffme commented 1 year ago

Do you mean @template-covariant? This has been supported since a long time: https://psalm.dev/docs/annotating_code/templated_annotations/#template-covariance

VincentLanglet commented 1 year ago

Do you mean @template-covariant? This has been supported since a long time: psalm.dev/docs/annotating_code/templated_annotations/#template-covariance

No, I mean https://phpstan.org/blog/guide-to-call-site-generic-variance#call-site-variance

It's when you use

/** @param Collection<covariant Animal> $animals */

to enjoy some of the covariant feature for a non-covariant template in a specific method.

See https://phpstan.org/r/5689cf72-aca5-4bbc-9593-1ffdf182731b for example.

vudaltsov commented 1 year ago

That would be awesome!