Skip to content

Commit ff96cba

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

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/PhpDoc/TypeNodeResolver.php

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

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

0 commit comments

Comments
 (0)