From 5264b0361e80d410004c3338c0a2618cd3c9bde1 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 2 Mar 2026 09:28:58 +0100 Subject: [PATCH] TemplateTypeTrait: Prevent unnecessary work --- src/Type/Generic/TemplateTypeTrait.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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()) {