Skip to content

Commit 956ea9e

Browse files
phpstan-botclaude
andcommitted
Skip keys absent from the other array instead of falling back to getIterableValueType()
When intersecting two ConstantArrayTypes and hasOffsetValueType() returns no for a key, that key cannot exist in the intersection. Previously it fell back to getIterableValueType() which could leak unrelated value types. Now those keys are simply skipped via continue. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 40f7eda commit 956ea9e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/Type/TypeCombinator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,12 +1495,12 @@ public static function intersect(Type ...$types): Type
14951495
$valueTypes = $types[$i]->getValueTypes();
14961496
foreach ($types[$i]->getKeyTypes() as $k => $keyType) {
14971497
$hasOffset = $types[$j]->hasOffsetValueType($keyType);
1498-
$otherValueType = !$hasOffset->no()
1499-
? $types[$j]->getOffsetValueType($keyType)
1500-
: $types[$j]->getIterableValueType();
1498+
if ($hasOffset->no()) {
1499+
continue;
1500+
}
15011501
$newArray->setOffsetValueType(
15021502
self::intersect($keyType, $types[$j]->getIterableKeyType()),
1503-
self::intersect($valueTypes[$k], $otherValueType),
1503+
self::intersect($valueTypes[$k], $types[$j]->getOffsetValueType($keyType)),
15041504
$types[$i]->isOptionalKey($k) && !$hasOffset->yes(),
15051505
);
15061506
}
@@ -1515,12 +1515,12 @@ public static function intersect(Type ...$types): Type
15151515
$valueTypes = $types[$j]->getValueTypes();
15161516
foreach ($types[$j]->getKeyTypes() as $k => $keyType) {
15171517
$hasOffset = $types[$i]->hasOffsetValueType($keyType);
1518-
$otherValueType = !$hasOffset->no()
1519-
? $types[$i]->getOffsetValueType($keyType)
1520-
: $types[$i]->getIterableValueType();
1518+
if ($hasOffset->no()) {
1519+
continue;
1520+
}
15211521
$newArray->setOffsetValueType(
15221522
self::intersect($keyType, $types[$i]->getIterableKeyType()),
1523-
self::intersect($valueTypes[$k], $otherValueType),
1523+
self::intersect($valueTypes[$k], $types[$i]->getOffsetValueType($keyType)),
15241524
$types[$j]->isOptionalKey($k) && !$hasOffset->yes(),
15251525
);
15261526
}

0 commit comments

Comments
 (0)