Skip to content

Infinite loop #3866

@enumag

Description

@enumag

Bug report

I added a new test today and PHPStan never finishes when trying to analyze it. Posting a reproducer below.

Code snippet that reproduces the problem

As this is causing an infinite loop I can't get a phpstan.org link. But if you copypaste the code, it will happen.

<?php declare(strict_types = 1);

use DateTimeImmutable;
use Ds\Set;
use Iterator;

abstract class PHPStanBug
{
	public function test(): void
	{
		/** @var Set<class-string> $set */
		$set = new Set();
		foreach ($this->a() as $item) {
			$set->add(\get_class($item));
		}
		foreach ($this->b() as $item) {
			$set->add(\get_class($item));
		}
		foreach ($this->c() as $item) {
			$set->add($item);
		}
		$set->sort();
	}

	/**
	 * @return Iterator<object>
	 */
	abstract public function a(): Iterator;

	/**
	 * @return Iterator<object>
	 */
	private function b(): Iterator
	{
		yield new DateTimeImmutable();
	}

	/**
	 * @return Iterator<class-string<object>>
	 */
	private function c(): Iterator
	{
		yield DateTimeImmutable::class;
	}
}

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