Skip to content

Commit 661babe

Browse files
authored
TemplateTypeTrait: Prevent unnecessary work
1 parent 0a4583d commit 661babe

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Type/Generic/TemplateTypeTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,14 @@ public function inferTemplateTypes(Type $receivedType): TemplateTypeMap
282282
TemplateTypeVarianceMap::createEmpty(),
283283
TemplateTypeVariance::createStatic(),
284284
));
285-
if ($resolvedBound->isSuperTypeOf($receivedType)->yes()) {
285+
$boundMatches = $resolvedBound->isSuperTypeOf($receivedType);
286+
if ($boundMatches->yes()) {
286287
return (new TemplateTypeMap([
287288
$this->name => $receivedType,
288289
]))->union($map);
289290
}
290291

291-
if ($receivedType instanceof UnionType) {
292+
if ($boundMatches->maybe() && $receivedType instanceof UnionType) {
292293
$matchingTypes = [];
293294
foreach ($receivedType->getTypes() as $innerType) {
294295
if (!$resolvedBound->isSuperTypeOf($innerType)->yes()) {

0 commit comments

Comments
 (0)