Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Type/Generic/GenericObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IsSuperTypeOfResult;
use PHPStan\Type\ObjectType;
use PHPStan\Type\RecursionGuard;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
Expand Down Expand Up @@ -95,7 +96,11 @@ public function getReferencedClasses(): array
{
$classes = parent::getReferencedClasses();
foreach ($this->types as $type) {
foreach ($type->getReferencedClasses() as $referencedClass) {
$referencedClasses = RecursionGuard::runOnObjectIdentity($type, static fn () => $type->getReferencedClasses());
if ($referencedClasses instanceof ErrorType) {
continue;
}
foreach ($referencedClasses as $referencedClass) {
$classes[] = $referencedClass;
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,13 @@ public function testBug14324(): void
$this->assertNoErrors($errors);
}

public function testBug13801(): void
{
// endless loop crash
$errors = $this->runAnalyse(__DIR__ . '/data/bug-13801.php');
$this->assertNoErrors($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return list<Error>
Expand Down
19 changes: 19 additions & 0 deletions tests/PHPStan/Analyser/data/bug-13801.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Bug13801;

/**
* @template TValue of object
*/
interface Cast
{
}

/**
* @template TCast of Cast<static>
*/
interface Castable
{
}
Loading