|
109 | 109 | use function array_map; |
110 | 110 | use function array_merge; |
111 | 111 | use function array_pop; |
112 | | -use function array_reverse; |
113 | 112 | use function array_slice; |
114 | 113 | use function array_unique; |
115 | 114 | use function array_values; |
@@ -2671,53 +2670,25 @@ private function propagateRefTypeToArrayDimFetch( |
2671 | 2670 | string $variableName, |
2672 | 2671 | ): self |
2673 | 2672 | { |
2674 | | - // Collect the chain of ArrayDimFetch from leaf to root |
2675 | | - $dimStack = []; |
2676 | | - $current = $targetExpr; |
2677 | | - while ($current instanceof Expr\ArrayDimFetch) { |
2678 | | - $dimStack[] = $current->dim; |
2679 | | - $current = $current->var; |
2680 | | - } |
2681 | | - |
2682 | | - // Build intermediate types from root to leaf |
2683 | | - $dimStack = array_reverse($dimStack); |
2684 | | - $rootType = $scope->getType($current); |
2685 | | - $rootNativeType = $scope->getNativeType($current); |
2686 | | - |
2687 | | - $intermediateTypes = [$rootType]; |
2688 | | - $intermediateNativeTypes = [$rootNativeType]; |
2689 | | - $currentType = $rootType; |
2690 | | - $currentNativeType = $rootNativeType; |
2691 | | - for ($i = 0; $i < count($dimStack) - 1; $i++) { |
2692 | | - $dim = $dimStack[$i]; |
2693 | | - if ($dim === null) { |
2694 | | - return $scope->assignExpression($targetExpr, $newType, $newNativeType); |
2695 | | - } |
2696 | | - $dimType = $scope->getType($dim)->toArrayKey(); |
2697 | | - $currentType = $currentType->getOffsetValueType($dimType); |
2698 | | - $currentNativeType = $currentNativeType->getOffsetValueType($dimType); |
2699 | | - $intermediateTypes[] = $currentType; |
2700 | | - $intermediateNativeTypes[] = $currentNativeType; |
2701 | | - } |
| 2673 | + $expr = $targetExpr; |
| 2674 | + $type = $newType; |
| 2675 | + $nativeType = $newNativeType; |
2702 | 2676 |
|
2703 | | - // Build up from the leaf using setOffsetValueType |
2704 | | - $builtType = $newType; |
2705 | | - $builtNativeType = $newNativeType; |
2706 | | - for ($i = count($dimStack) - 1; $i >= 0; $i--) { |
2707 | | - $dim = $dimStack[$i]; |
2708 | | - if ($dim === null) { |
| 2677 | + while ($expr instanceof Expr\ArrayDimFetch) { |
| 2678 | + if ($expr->dim === null) { |
2709 | 2679 | return $scope->assignExpression($targetExpr, $newType, $newNativeType); |
2710 | 2680 | } |
2711 | | - $dimType = $scope->getType($dim)->toArrayKey(); |
2712 | | - $builtType = $intermediateTypes[$i]->setOffsetValueType($dimType, $builtType); |
2713 | | - $builtNativeType = $intermediateNativeTypes[$i]->setOffsetValueType($dimType, $builtNativeType); |
| 2681 | + $dimType = $scope->getType($expr->dim)->toArrayKey(); |
| 2682 | + $type = $scope->getType($expr->var)->setOffsetValueType($dimType, $type); |
| 2683 | + $nativeType = $scope->getNativeType($expr->var)->setOffsetValueType($dimType, $nativeType); |
| 2684 | + $expr = $expr->var; |
2714 | 2685 | } |
2715 | 2686 |
|
2716 | | - if ($current instanceof Variable && is_string($current->name)) { |
| 2687 | + if ($expr instanceof Variable && is_string($expr->name)) { |
2717 | 2688 | return $scope->assignVariable( |
2718 | | - $current->name, |
2719 | | - $builtType, |
2720 | | - $builtNativeType, |
| 2689 | + $expr->name, |
| 2690 | + $type, |
| 2691 | + $nativeType, |
2721 | 2692 | TrinaryLogic::createYes(), |
2722 | 2693 | array_merge($intertwinedPropagatedFrom, [$variableName]), |
2723 | 2694 | ); |
|
0 commit comments