You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PHPStan rejects @var static<string> on a factory result when the class implements IteratorAggregate #15796
Items<T> implements IteratorAggregate<int, T>. Its make() method creates a new collection from the values passed to it and returns static<U>, where U is the type of those values. When I pass a list of strings, PHPStan accepts the result as static<string> until I add an inline @var saying the same thing:
On line 34 PHPStan reports PHPDoc tag @var with type static(Items<string>) is not subtype of native type static(Items<T>). If I remove just the @var, PHPStan itself reports static(Items<string>) for $names with dumpType(). If I keep the annotation but remove the IteratorAggregate interface and its @implements and #[\Override] annotations, the example also passes. Implementing a generic custom interface (@implements Bag<T>) instead doesn't trigger it.
This passes on 2.3.2 and fails on 2.3.3, 2.3.7 and the current 2.3.x branch.
Activity