psalm
psalm copied to clipboard
Iterator stubs not validated and broken?
Hi, I just got this pull request https://github.com/phpstan/phpstan-src/pull/796 and I want PHPStan and Psalm's generic stubs to be compatible so I cross-checked how the stubs for these classes look here.
I noticed that Psalm's IteratorIterator looks like this:
/**
* @template-covariant TKey
* @template-covariant TValue
* @template TIterator as Traversable<TKey, TValue>
*
* @template-implements OuterIterator<TKey, TValue>
*
* @mixin TIterator
*/
class IteratorIterator implements OuterIterator {
Which is the same as in PHPStan. But a class that extends it looks differently:
/**
* @template-covariant TKey
* @template-covariant TValue
*
* @template-extends IteratorIterator<TKey, TValue>
*/
class FilterIterator extends IteratorIterator {
Somehow Psalm doesn't care that IteratorIterator has three @template
s and accepts just IteratorIterator<TKey, TValue>
. Normally it's a reported error ("ERROR: MissingTemplateParam - 21:7 - Bar has missing template params when extending Foo , expecting 3") but not here.
PHPStan's stubs are validated regardless of the user's rule level with a few selected rules that make sense for stubs, so maybe Psalm should do the same.
Hey @ondrejmirtes, can you reproduce the issue on https://psalm.dev ?
Seems like Stubs are scanned but not analyzed. Due to how Psalm runs, I don't think we can just select what we want to check and what we don't want. Worse, when trying to analyze, Psalm sees that those classes already exists, emit an error and just stop the analysis.
I prepared a PR to fix the errors on stubs, but I'm not sure we can do better than that...
The original issue with stubs is fixed, but we still need to find a way to validate them.