Skip to content

Commit 09cda43

Browse files
committed
fix generic alias resolution: skip alias path when name resolves to a known class
1 parent ccbcd95 commit 09cda43

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/PhpDoc/TypeNodeResolver.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,15 @@ static function (string $variance): TemplateTypeVariance {
840840
return new ErrorType();
841841
}
842842

843-
// Check for a generic type alias (e.g. ProviderRequest<AppraisalFilter>) before
844-
// falling through to class-based generic resolution.
845-
$genericTypeAlias = $this->findGenericTypeAlias($typeNode->type->name, $nameScope);
843+
// Check for a generic type alias (e.g. MyList<string>) before falling through to
844+
// class-based generic resolution, but only when the name is not itself a resolvable
845+
// class — in that case the class-based path must win to preserve backward compatibility
846+
// (a type alias like BelongsTo<T, U> = \Eloquent\BelongsTo<T, U> should still produce
847+
// the same GenericObjectType that class-based resolution would have given).
848+
$resolvedGenericName = $nameScope->resolveStringName($typeNode->type->name);
849+
$genericTypeAlias = !$this->getReflectionProvider()->hasClass($resolvedGenericName)
850+
? $this->findGenericTypeAlias($typeNode->type->name, $nameScope)
851+
: null;
846852
if ($genericTypeAlias !== null) {
847853
$templateNodes = $genericTypeAlias->getTemplateTagValueNodes();
848854
$totalParams = count($templateNodes);

0 commit comments

Comments
 (0)