@@ -1543,42 +1543,33 @@ public static function intersect(Type ...$types): Type
15431543 continue 2 ;
15441544 }
15451545
1546- if ($ types [$ i ] instanceof ConstantArrayType && ($ types [$ j ] instanceof ArrayType || $ types [$ j ] instanceof ConstantArrayType)) {
1546+ $ constArrayIsI = $ types [$ i ] instanceof ConstantArrayType && ($ types [$ j ] instanceof ArrayType || $ types [$ j ] instanceof ConstantArrayType);
1547+ $ constArrayIsJ = $ types [$ j ] instanceof ConstantArrayType && ($ types [$ i ] instanceof ArrayType || $ types [$ i ] instanceof ConstantArrayType);
1548+ if ($ constArrayIsI || $ constArrayIsJ ) {
1549+ $ constArray = $ constArrayIsI ? $ types [$ i ] : $ types [$ j ];
1550+ $ otherArray = $ constArrayIsI ? $ types [$ j ] : $ types [$ i ];
1551+
15471552 $ newArray = ConstantArrayTypeBuilder::createEmpty ();
1548- $ valueTypes = $ types [ $ i ] ->getValueTypes ();
1549- foreach ($ types [ $ i ] ->getKeyTypes () as $ k => $ keyType ) {
1550- $ hasOffset = $ types [ $ j ] ->hasOffsetValueType ($ keyType );
1553+ $ valueTypes = $ constArray ->getValueTypes ();
1554+ foreach ($ constArray ->getKeyTypes () as $ k => $ keyType ) {
1555+ $ hasOffset = $ otherArray ->hasOffsetValueType ($ keyType );
15511556 if ($ hasOffset ->no ()) {
15521557 continue ;
15531558 }
15541559 $ newArray ->setOffsetValueType (
1555- self ::intersect ($ keyType , $ types [ $ j ] ->getIterableKeyType ()),
1556- self ::intersect ($ valueTypes [$ k ], $ types [ $ j ] ->getOffsetValueType ($ keyType )),
1557- $ types [ $ i ] ->isOptionalKey ($ k ) && !$ hasOffset ->yes (),
1560+ self ::intersect ($ keyType , $ otherArray ->getIterableKeyType ()),
1561+ self ::intersect ($ valueTypes [$ k ], $ otherArray ->getOffsetValueType ($ keyType )),
1562+ $ constArray ->isOptionalKey ($ k ) && !$ hasOffset ->yes (),
15581563 );
15591564 }
1560- $ types [$ i ] = $ newArray ->getArray ();
1561- array_splice ($ types , $ j --, 1 );
1562- $ typesCount --;
1563- continue 2 ;
1564- }
15651565
1566- if ($ types [$ j ] instanceof ConstantArrayType && ($ types [$ i ] instanceof ArrayType || $ types [$ i ] instanceof ConstantArrayType)) {
1567- $ newArray = ConstantArrayTypeBuilder::createEmpty ();
1568- $ valueTypes = $ types [$ j ]->getValueTypes ();
1569- foreach ($ types [$ j ]->getKeyTypes () as $ k => $ keyType ) {
1570- $ hasOffset = $ types [$ i ]->hasOffsetValueType ($ keyType );
1571- if ($ hasOffset ->no ()) {
1572- continue ;
1573- }
1574- $ newArray ->setOffsetValueType (
1575- self ::intersect ($ keyType , $ types [$ i ]->getIterableKeyType ()),
1576- self ::intersect ($ valueTypes [$ k ], $ types [$ i ]->getOffsetValueType ($ keyType )),
1577- $ types [$ j ]->isOptionalKey ($ k ) && !$ hasOffset ->yes (),
1578- );
1566+ if ($ constArrayIsI ) {
1567+ $ types [$ i ] = $ newArray ->getArray ();
1568+ array_splice ($ types , $ j --, 1 );
1569+ } else {
1570+ $ types [$ j ] = $ newArray ->getArray ();
1571+ array_splice ($ types , $ i --, 1 );
15791572 }
1580- $ types [$ j ] = $ newArray ->getArray ();
1581- array_splice ($ types , $ i --, 1 );
15821573 $ typesCount --;
15831574 continue 2 ;
15841575 }
0 commit comments