diff --git a/src/Type/Generic/TemplateTypeTrait.php b/src/Type/Generic/TemplateTypeTrait.php index aa6b5e17c09..d823f9b20d5 100644 --- a/src/Type/Generic/TemplateTypeTrait.php +++ b/src/Type/Generic/TemplateTypeTrait.php @@ -282,13 +282,14 @@ public function inferTemplateTypes(Type $receivedType): TemplateTypeMap TemplateTypeVarianceMap::createEmpty(), TemplateTypeVariance::createStatic(), )); - if ($resolvedBound->isSuperTypeOf($receivedType)->yes()) { + $boundMatches = $resolvedBound->isSuperTypeOf($receivedType); + if ($boundMatches->yes()) { return (new TemplateTypeMap([ $this->name => $receivedType, ]))->union($map); } - if ($receivedType instanceof UnionType) { + if ($boundMatches->maybe() && $receivedType instanceof UnionType) { $matchingTypes = []; foreach ($receivedType->getTypes() as $innerType) { if (!$resolvedBound->isSuperTypeOf($innerType)->yes()) {