Skip to content

Commit 90d9ac9

Browse files
committed
Update ConstantArrayType.php
1 parent b304060 commit 90d9ac9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Type/Constant/ConstantArrayType.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,12 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $uni
702702
{
703703
if ($offsetType !== null) {
704704
$scalarKeyTypes = $this->resolveFiniteScalarKeyTypes($offsetType);
705-
if ($scalarKeyTypes !== null && count($scalarKeyTypes) >= 2) {
705+
// turn into tagged union for more precise results
706+
if (
707+
$scalarKeyTypes !== null
708+
&& count($scalarKeyTypes) >= 2
709+
&& count($scalarKeyTypes) <= self::CHUNK_FINITE_TYPES_LIMIT
710+
) {
706711
$hasNewKey = false;
707712
foreach ($scalarKeyTypes as $scalarKeyType) {
708713
$existingKeyFound = false;
@@ -770,11 +775,7 @@ private function resolveFiniteScalarKeyTypes(Type $offsetType): ?array
770775
}
771776
}
772777

773-
if (count($result) <= self::CHUNK_FINITE_TYPES_LIMIT) {
774-
return $result;
775-
}
776-
777-
return null;
778+
return $result;
778779
}
779780

780781
public function unsetOffset(Type $offsetType): Type

0 commit comments

Comments
 (0)