Skip to content

@implement tag on RecursiveIterator returns an error, while Iterator does not #4718

@jfcalcerrada

Description

@jfcalcerrada

Bug report

@implements tag on a \RecursiveIterator doesn't work, but it does with \Iterator.

The following error is being reported:

Class Some\Foo\PeriodRecursive @implements tag contains incompatible type iterable<Some\Foo\Moment>&RecursiveIterator.

Digging into the source code, I found this commit "reverting" the change: phpstan/phpstan-src@aa92b5b

So I assume this is not a bug and it's intentional, but I'm not understanding why this was reverted.

Code snippet that reproduces the problem

Link to the playground, please ignore missing method errors:

https://phpstan.org/r/f5382215-922f-4453-a7d6-de0ae9a524d6

<?php namespace Some\Foo;

class Moment {}

/**
 * @implements \Iterator<Moment>
 */
final class Period implements \Iterator
{
}

/**
 * @implements \RecursiveIterator<Moment>
 */
final class PeriodRecursive implements \RecursiveIterator
{
}

Expected output

No error is returned, as \RecursiveIterator works the same as \Iterator

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions