Skip to content

Commit

Permalink
processAssignVar optimization for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 26, 2024
1 parent c54b257 commit 16f63b3
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5078,7 +5078,30 @@ private function processAssignVar(
$offsetNativeValueType = $varNativeType;

$valueToWrite = $this->produceArrayDimFetchAssignValueToWrite($offsetTypes, $offsetValueType, $valueToWrite);
$nativeValueToWrite = $this->produceArrayDimFetchAssignValueToWrite($offsetNativeTypes, $offsetNativeValueType, $nativeValueToWrite);

$nativeValueToWrite = $valueToWrite;
if (!$offsetValueType->equals($offsetNativeValueType) || !$valueToWrite->equals($nativeValueToWrite)) {
$nativeValueToWrite = $this->produceArrayDimFetchAssignValueToWrite($offsetNativeTypes, $offsetNativeValueType, $nativeValueToWrite);
} else {
foreach ($offsetTypes as $i => $offsetType) {
$offsetNativeType = $offsetNativeTypes[$i];
if ($offsetType === null) {
if ($offsetNativeType !== null) {
throw new ShouldNotHappenException();
}

continue;
} elseif ($offsetNativeType === null) {
throw new ShouldNotHappenException();
}
if ($offsetType->equals($offsetNativeType)) {
continue;
}

$nativeValueToWrite = $this->produceArrayDimFetchAssignValueToWrite($offsetNativeTypes, $offsetNativeValueType, $nativeValueToWrite);
break;
}
}

if ($varType->isArray()->yes() || !(new ObjectType(ArrayAccess::class))->isSuperTypeOf($varType)->yes()) {
if ($var instanceof Variable && is_string($var->name)) {
Expand Down

0 comments on commit 16f63b3

Please sign in to comment.