@@ -5659,12 +5659,12 @@ private function processAssignVar(
5659
5659
}
5660
5660
5661
5661
if ($ dimExpr === null ) {
5662
- $ offsetTypes [] = null ;
5663
- $ offsetNativeTypes [] = null ;
5662
+ $ offsetTypes [] = [ null , $ dimFetch ] ;
5663
+ $ offsetNativeTypes [] = [ null , $ dimFetch ] ;
5664
5664
5665
5665
} else {
5666
- $ offsetTypes [] = $ scope ->getType ($ dimExpr );
5667
- $ offsetNativeTypes [] = $ scope ->getNativeType ($ dimExpr );
5666
+ $ offsetTypes [] = [ $ scope ->getType ($ dimExpr ), $ dimFetch ] ;
5667
+ $ offsetNativeTypes [] = [ $ scope ->getNativeType ($ dimExpr ), $ dimFetch ] ;
5668
5668
5669
5669
if ($ enterExpressionAssign ) {
5670
5670
$ scope ->enterExpressionAssign ($ dimExpr );
@@ -5712,8 +5712,8 @@ private function processAssignVar(
5712
5712
[$ nativeValueToWrite , $ additionalNativeExpressions ] = $ this ->produceArrayDimFetchAssignValueToWrite ($ dimFetchStack , $ offsetNativeTypes , $ offsetNativeValueType , $ nativeValueToWrite , $ scope );
5713
5713
} else {
5714
5714
$ rewritten = false ;
5715
- foreach ($ offsetTypes as $ i => $ offsetType ) {
5716
- $ offsetNativeType = $ offsetNativeTypes [$ i ];
5715
+ foreach ($ offsetTypes as $ i => [ $ offsetType] ) {
5716
+ [ $ offsetNativeType] = $ offsetNativeTypes [$ i ];
5717
5717
5718
5718
if ($ offsetType === null ) {
5719
5719
if ($ offsetNativeType !== null ) {
@@ -6046,8 +6046,8 @@ static function (): void {
6046
6046
$ offsetNativeTypes = [];
6047
6047
foreach (array_reverse ($ dimFetchStack ) as $ dimFetch ) {
6048
6048
$ dimExpr = $ dimFetch ->getDim ();
6049
- $ offsetTypes [] = $ scope ->getType ($ dimExpr );
6050
- $ offsetNativeTypes [] = $ scope ->getNativeType ($ dimExpr );
6049
+ $ offsetTypes [] = [ $ scope ->getType ($ dimExpr ), $ dimFetch ] ;
6050
+ $ offsetNativeTypes [] = [ $ scope ->getNativeType ($ dimExpr ), $ dimFetch ] ;
6051
6051
}
6052
6052
6053
6053
$ valueToWrite = $ scope ->getType ($ assignedExpr );
@@ -6059,21 +6059,21 @@ static function (): void {
6059
6059
$ offsetNativeValueType = $ varNativeType ;
6060
6060
$ offsetValueTypeStack = [$ offsetValueType ];
6061
6061
$ offsetValueNativeTypeStack = [$ offsetNativeValueType ];
6062
- foreach (array_slice ($ offsetTypes , 0 , -1 ) as $ offsetType ) {
6062
+ foreach (array_slice ($ offsetTypes , 0 , -1 ) as [ $ offsetType] ) {
6063
6063
$ offsetValueType = $ offsetValueType ->getOffsetValueType ($ offsetType );
6064
6064
$ offsetValueTypeStack [] = $ offsetValueType ;
6065
6065
}
6066
- foreach (array_slice ($ offsetNativeTypes , 0 , -1 ) as $ offsetNativeType ) {
6066
+ foreach (array_slice ($ offsetNativeTypes , 0 , -1 ) as [ $ offsetNativeType] ) {
6067
6067
$ offsetNativeValueType = $ offsetNativeValueType ->getOffsetValueType ($ offsetNativeType );
6068
6068
$ offsetValueNativeTypeStack [] = $ offsetNativeValueType ;
6069
6069
}
6070
6070
6071
- foreach (array_reverse ($ offsetTypes ) as $ offsetType ) {
6071
+ foreach (array_reverse ($ offsetTypes ) as [ $ offsetType] ) {
6072
6072
/** @var Type $offsetValueType */
6073
6073
$ offsetValueType = array_pop ($ offsetValueTypeStack );
6074
6074
$ valueToWrite = $ offsetValueType ->setExistingOffsetValueType ($ offsetType , $ valueToWrite );
6075
6075
}
6076
- foreach (array_reverse ($ offsetNativeTypes ) as $ offsetNativeType ) {
6076
+ foreach (array_reverse ($ offsetNativeTypes ) as [ $ offsetNativeType] ) {
6077
6077
/** @var Type $offsetNativeValueType */
6078
6078
$ offsetNativeValueType = array_pop ($ offsetValueNativeTypeStack );
6079
6079
$ nativeValueToWrite = $ offsetNativeValueType ->setExistingOffsetValueType ($ offsetNativeType , $ nativeValueToWrite );
@@ -6143,7 +6143,7 @@ private function isImplicitArrayCreation(array $dimFetchStack, Scope $scope): Tr
6143
6143
6144
6144
/**
6145
6145
* @param list<ArrayDimFetch> $dimFetchStack
6146
- * @param list<Type|null> $offsetTypes
6146
+ * @param list<array{ Type|null, ArrayDimFetch} > $offsetTypes
6147
6147
*
6148
6148
* @return array{Type, list<array{Expr, Type}>}
6149
6149
*/
@@ -6152,21 +6152,24 @@ private function produceArrayDimFetchAssignValueToWrite(array $dimFetchStack, ar
6152
6152
$ originalValueToWrite = $ valueToWrite ;
6153
6153
6154
6154
$ offsetValueTypeStack = [$ offsetValueType ];
6155
- foreach (array_slice ($ offsetTypes , 0 , -1 ) as $ offsetType ) {
6155
+ foreach (array_slice ($ offsetTypes , 0 , -1 ) as [ $ offsetType, $ dimFetch ] ) {
6156
6156
if ($ offsetType === null ) {
6157
6157
$ offsetValueType = new ConstantArrayType ([], []);
6158
6158
6159
6159
} else {
6160
+ $ add = $ offsetValueType ->hasOffsetValueType ($ offsetType )->maybe ();
6160
6161
$ offsetValueType = $ offsetValueType ->getOffsetValueType ($ offsetType );
6161
6162
if ($ offsetValueType instanceof ErrorType) {
6162
6163
$ offsetValueType = new ConstantArrayType ([], []);
6164
+ } elseif ($ add && !$ scope ->hasExpressionType ($ dimFetch )->yes ()) {
6165
+ $ offsetValueType = TypeCombinator::union ($ offsetValueType , new ConstantArrayType ([], []));
6163
6166
}
6164
6167
}
6165
6168
6166
6169
$ offsetValueTypeStack [] = $ offsetValueType ;
6167
6170
}
6168
6171
6169
- foreach (array_reverse ($ offsetTypes ) as $ i => $ offsetType ) {
6172
+ foreach (array_reverse ($ offsetTypes ) as $ i => [ $ offsetType] ) {
6170
6173
/** @var Type $offsetValueType */
6171
6174
$ offsetValueType = array_pop ($ offsetValueTypeStack );
6172
6175
if (
0 commit comments