@@ -390,22 +390,14 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
390390 ) {
391391 $ arrayArg = $ normalizedExpr ->getArgs ()[0 ]->value ;
392392
393- $ callArgs = array_slice ($ normalizedExpr ->getArgs (), 1 );
394- $ callArgTypes = [];
395- $ callArgNativeTypes = [];
396- foreach ($ callArgs as $ callArg ) {
397- $ callArgTypes [] = $ scopeBeforeArgs ->getType ($ callArg ->value );
398- $ callArgNativeTypes [] = $ scopeBeforeArgs ->getNativeType ($ callArg ->value );
399- }
400-
401393 $ scope = $ nodeScopeResolver ->processVirtualAssign (
402394 $ scope ,
403395 $ storage ,
404396 $ stmt ,
405397 $ arrayArg ,
406398 new NativeTypeExpr (
407- $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scope , $ normalizedExpr, $ callArgTypes ),
408- $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scope ->doNotTreatPhpDocTypesAsCertain (), $ normalizedExpr, $ callArgNativeTypes ),
399+ $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scopeBeforeArgs , $ normalizedExpr ),
400+ $ this ->getArrayFunctionAppendingType ($ functionReflection , $ scopeBeforeArgs ->doNotTreatPhpDocTypesAsCertain (), $ normalizedExpr ),
409401 ),
410402 $ nodeCallback ,
411403 )->getScope ();
@@ -643,23 +635,19 @@ private function getFunctionThrowPoint(
643635 return null ;
644636 }
645637
646- /**
647- * @param Type[] $precomputedArgTypes
648- */
649- private function getArrayFunctionAppendingType (FunctionReflection $ functionReflection , Scope $ scope , FuncCall $ expr , array $ precomputedArgTypes ): Type
638+ private function getArrayFunctionAppendingType (FunctionReflection $ functionReflection , Scope $ scope , FuncCall $ expr ): Type
650639 {
651640 $ arrayArg = $ expr ->getArgs ()[0 ]->value ;
652641 $ arrayType = $ scope ->getType ($ arrayArg );
653642 $ callArgs = array_slice ($ expr ->getArgs (), 1 );
654643
655644 /**
656645 * @param Arg[] $callArgs
657- * @param Type[] $precomputedArgTypes
658646 * @param callable(?Type, Type, bool): void $setOffsetValueType
659647 */
660- $ setOffsetValueTypes = static function (array $ callArgs , callable $ setOffsetValueType , array $ precomputedArgTypes , ?bool &$ nonConstantArrayWasUnpacked = null ): void {
661- foreach ($ callArgs as $ i => $ callArg ) {
662- $ callArgType = $ precomputedArgTypes [ $ i ] ;
648+ $ setOffsetValueTypes = static function (Scope $ scope , array $ callArgs , callable $ setOffsetValueType , ?bool &$ nonConstantArrayWasUnpacked = null ): void {
649+ foreach ($ callArgs as $ callArg ) {
650+ $ callArgType = $ scope -> getType ( $ callArg -> value ) ;
663651 if ($ callArg ->unpack ) {
664652 $ constantArrays = $ callArgType ->getConstantArrays ();
665653 if (count ($ constantArrays ) === 1 ) {
@@ -693,11 +681,11 @@ private function getArrayFunctionAppendingType(FunctionReflection $functionRefle
693681 $ arrayTypeBuilder = $ prepend ? ConstantArrayTypeBuilder::createEmpty () : ConstantArrayTypeBuilder::createFromConstantArray ($ constantArray );
694682
695683 $ setOffsetValueTypes (
684+ $ scope ,
696685 $ callArgs ,
697686 static function (?Type $ offsetType , Type $ valueType , bool $ optional ) use (&$ arrayTypeBuilder ): void {
698687 $ arrayTypeBuilder ->setOffsetValueType ($ offsetType , $ valueType , $ optional );
699688 },
700- $ precomputedArgTypes ,
701689 $ nonConstantArrayWasUnpacked ,
702690 );
703691
@@ -733,6 +721,7 @@ static function (?Type $offsetType, Type $valueType, bool $optional) use (&$arra
733721 }
734722
735723 $ setOffsetValueTypes (
724+ $ scope ,
736725 $ callArgs ,
737726 static function (?Type $ offsetType , Type $ valueType , bool $ optional ) use (&$ arrayType ): void {
738727 $ isIterableAtLeastOnce = $ arrayType ->isIterableAtLeastOnce ()->yes () || !$ optional ;
@@ -743,7 +732,6 @@ static function (?Type $offsetType, Type $valueType, bool $optional) use (&$arra
743732
744733 $ arrayType = TypeCombinator::union ($ arrayType , new ConstantArrayType ([], []));
745734 },
746- $ precomputedArgTypes ,
747735 );
748736
749737 return $ arrayType ;
0 commit comments