Skip to content

Commit f37b59d

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

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
@@ -874,9 +874,15 @@ static function (string $variance): TemplateTypeVariance {
874874
return new ErrorType();
875875
}
876876

877-
// Check for a generic type alias (e.g. ProviderRequest<AppraisalFilter>) before
878-
// falling through to class-based generic resolution.
879-
$genericTypeAlias = $this->findGenericTypeAlias($typeNode->type->name, $nameScope);
877+
// Check for a generic type alias (e.g. MyList<string>) before falling through to
878+
// class-based generic resolution, but only when the name is not itself a resolvable
879+
// class — in that case the class-based path must win to preserve backward compatibility
880+
// (a type alias like BelongsTo<T, U> = \Eloquent\BelongsTo<T, U> should still produce
881+
// the same GenericObjectType that class-based resolution would have given).
882+
$resolvedGenericName = $nameScope->resolveStringName($typeNode->type->name);
883+
$genericTypeAlias = !$this->getReflectionProvider()->hasClass($resolvedGenericName)
884+
? $this->findGenericTypeAlias($typeNode->type->name, $nameScope)
885+
: null;
880886
if ($genericTypeAlias !== null) {
881887
$templateNodes = $genericTypeAlias->getTemplateTagValueNodes();
882888
$totalParams = count($templateNodes);

0 commit comments

Comments
 (0)