-
-
Notifications
You must be signed in to change notification settings - Fork 946
Closed
Description
Bug report
When implementing a specific configuration of "nestable" iterable types, PHPStan will produce errors that claim "no value type specified in iterable type" for types that have been explicitly "un-genericised" using PHPDoc annotations.
This is a pretty strange use case that has been distilled from a more complex real-world case. The actual versions of the types represented here are:
Collectionis equivalent toEventCollectionMemberis equivalent toCallMemberImplis equivalent toCallDataCollectionImplis equivalent toEventSequence
Code snippet that reproduces the problem
From https://phpstan.org/r/2594d7d7-d75e-4916-b924-f2120ab028c2:
<?php
/**
* A collection that can contain members.
*
* @extends IteratorAggregate<int,Member>
*/
interface Collection extends IteratorAggregate
{
}
/**
* A member of a collection. Also a collection containing only itself.
*
* In the real world, this would contain additional methods.
*/
interface Member extends Collection
{
}
class MemberImpl implements Member
{
/**
* @return Iterator<int,Member>
*/
public function getIterator(): Iterator
{
return new ArrayIterator([$this]);
}
}
class CollectionImpl implements Collection
{
public function __construct(Member ...$members)
{
$this->members = $members;
}
/**
* @return Member
*/
public function getMember(): Member
{
return new MemberImpl();
}
/**
* @return Iterator<int,Member>
*/
public function getIterator(): Iterator
{
return new ArrayIterator($this->members);
}
/**
* @var array<int,Member>
*/
private $members;
}Expected output
PHPStan should not produce an error. Instead it produces an error like:
Method CollectionImpl::getMember() return type has no value type specified in iterable type Member.
Reactions are currently unavailable