@@ -5756,24 +5756,26 @@ static function (): void {
5756
5756
*/
5757
5757
private function produceArrayDimFetchAssignValueToWrite (array $ offsetTypes , Type $ offsetValueType , Type $ valueToWrite ): Type
5758
5758
{
5759
- $ offsetValueTypeStack = [$ offsetValueType ];
5759
+ $ offsetValueTypeStack = [[ $ offsetValueType, TrinaryLogic:: createYes ()] ];
5760
5760
foreach (array_slice ($ offsetTypes , 0 , -1 ) as $ offsetType ) {
5761
5761
if ($ offsetType === null ) {
5762
+ $ has = TrinaryLogic::createYes ();
5762
5763
$ offsetValueType = new ConstantArrayType ([], []);
5763
5764
5764
5765
} else {
5766
+ $ has = $ offsetValueType ->hasOffsetValueType ($ offsetType );
5765
5767
$ offsetValueType = $ offsetValueType ->getOffsetValueType ($ offsetType );
5766
5768
if ($ offsetValueType instanceof ErrorType) {
5767
5769
$ offsetValueType = new ConstantArrayType ([], []);
5768
5770
}
5769
5771
}
5770
5772
5771
- $ offsetValueTypeStack [] = $ offsetValueType ;
5773
+ $ offsetValueTypeStack [] = [ $ offsetValueType, $ has ] ;
5772
5774
}
5773
5775
5774
5776
foreach (array_reverse ($ offsetTypes ) as $ i => $ offsetType ) {
5775
5777
/** @var Type $offsetValueType */
5776
- $ offsetValueType = array_pop ($ offsetValueTypeStack );
5778
+ [ $ offsetValueType, $ has ] = array_pop ($ offsetValueTypeStack );
5777
5779
if (
5778
5780
!$ offsetValueType instanceof MixedType
5779
5781
&& !$ offsetValueType ->isConstantArray ()->yes ()
@@ -5788,7 +5790,10 @@ private function produceArrayDimFetchAssignValueToWrite(array $offsetTypes, Type
5788
5790
}
5789
5791
$ offsetValueType = TypeCombinator::intersect ($ offsetValueType , TypeCombinator::union (...$ types ));
5790
5792
}
5791
- $ valueToWrite = $ offsetValueType ->setOffsetValueType ($ offsetType , $ valueToWrite , $ i === 0 );
5793
+ if (!$ has ->yes ()) {
5794
+ $ offsetValueType = TypeCombinator::union ($ offsetValueType , new ConstantArrayType ([], []));
5795
+ }
5796
+ $ valueToWrite = $ offsetValueType ->setOffsetValueType ($ offsetType , $ valueToWrite );
5792
5797
}
5793
5798
5794
5799
return $ valueToWrite ;
0 commit comments