166
166
use function usort ;
167
167
use const PHP_INT_MAX ;
168
168
use const PHP_INT_MIN ;
169
+ use const PHP_VERSION_ID ;
169
170
170
171
final class MutatingScope implements Scope
171
172
{
@@ -5138,7 +5139,10 @@ private static function generalizeType(Type $a, Type $b, int $depth): Type
5138
5139
} else {
5139
5140
$ constantArraysA = TypeCombinator::union (...$ constantArrays ['a ' ]);
5140
5141
$ constantArraysB = TypeCombinator::union (...$ constantArrays ['b ' ]);
5141
- if ($ constantArraysA ->getIterableKeyType ()->equals ($ constantArraysB ->getIterableKeyType ())) {
5142
+ if (
5143
+ $ constantArraysA ->getIterableKeyType ()->equals ($ constantArraysB ->getIterableKeyType ())
5144
+ && $ constantArraysA ->getArraySize ()->equals ($ constantArraysB ->getArraySize ())
5145
+ ) {
5142
5146
$ resultArrayBuilder = ConstantArrayTypeBuilder::createEmpty ();
5143
5147
foreach (TypeUtils::flattenTypes ($ constantArraysA ->getIterableKeyType ()) as $ keyType ) {
5144
5148
$ resultArrayBuilder ->setOffsetValueType (
@@ -5158,7 +5162,11 @@ private static function generalizeType(Type $a, Type $b, int $depth): Type
5158
5162
TypeCombinator::union (self ::generalizeType ($ constantArraysA ->getIterableKeyType (), $ constantArraysB ->getIterableKeyType (), $ depth + 1 )),
5159
5163
TypeCombinator::union (self ::generalizeType ($ constantArraysA ->getIterableValueType (), $ constantArraysB ->getIterableValueType (), $ depth + 1 )),
5160
5164
);
5161
- if ($ constantArraysA ->isIterableAtLeastOnce ()->yes () && $ constantArraysB ->isIterableAtLeastOnce ()->yes ()) {
5165
+ if (
5166
+ $ constantArraysA ->isIterableAtLeastOnce ()->yes ()
5167
+ && $ constantArraysB ->isIterableAtLeastOnce ()->yes ()
5168
+ && $ constantArraysA ->getArraySize ()->getGreaterOrEqualType (new PhpVersion (PHP_VERSION_ID ))->isSuperTypeOf ($ constantArraysB ->getArraySize ())->yes ()
5169
+ ) {
5162
5170
$ resultType = TypeCombinator::intersect ($ resultType , new NonEmptyArrayType ());
5163
5171
}
5164
5172
if ($ constantArraysA ->isList ()->yes () && $ constantArraysB ->isList ()->yes ()) {
0 commit comments