Skip to content

Commit b65a8a0

Browse files
committed
Fix for ArrayAccess
1 parent 6cf8068 commit b65a8a0

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5344,9 +5344,17 @@ private function processAssignVar(
53445344
$originalVar = $var;
53455345
$assignedPropertyExpr = $assignedExpr;
53465346
while ($var instanceof ArrayDimFetch) {
5347-
$varForSetOffsetValue = $var->var;
5348-
if ($varForSetOffsetValue instanceof PropertyFetch || $varForSetOffsetValue instanceof StaticPropertyFetch) {
5349-
$varForSetOffsetValue = new OriginalPropertyTypeExpr($varForSetOffsetValue);
5347+
if (
5348+
$var->var instanceof PropertyFetch
5349+
|| $var->var instanceof StaticPropertyFetch
5350+
) {
5351+
if (((new ObjectType(ArrayAccess::class))->isSuperTypeOf($scope->getType($var->var))->yes())) {
5352+
$varForSetOffsetValue = $var->var;
5353+
} else {
5354+
$varForSetOffsetValue = new OriginalPropertyTypeExpr($var->var);
5355+
}
5356+
} else {
5357+
$varForSetOffsetValue = $var->var;
53505358
}
53515359
$assignedPropertyExpr = new SetOffsetValueTypeExpr(
53525360
$varForSetOffsetValue,
@@ -5682,9 +5690,17 @@ static function (): void {
56825690
$dimFetchStack = [];
56835691
$assignedPropertyExpr = $assignedExpr;
56845692
while ($var instanceof ExistingArrayDimFetch) {
5685-
$varForSetOffsetValue = $var->getVar();
5686-
if ($varForSetOffsetValue instanceof PropertyFetch || $varForSetOffsetValue instanceof StaticPropertyFetch) {
5687-
$varForSetOffsetValue = new OriginalPropertyTypeExpr($varForSetOffsetValue);
5693+
if (
5694+
$var->getVar() instanceof PropertyFetch
5695+
|| $var->getVar() instanceof StaticPropertyFetch
5696+
) {
5697+
if (((new ObjectType(ArrayAccess::class))->isSuperTypeOf($scope->getType($var->getVar()))->yes())) {
5698+
$varForSetOffsetValue = $var->getVar();
5699+
} else {
5700+
$varForSetOffsetValue = new OriginalPropertyTypeExpr($var->getVar());
5701+
}
5702+
} else {
5703+
$varForSetOffsetValue = $var->getVar();
56885704
}
56895705
$assignedPropertyExpr = new SetExistingOffsetValueTypeExpr(
56905706
$varForSetOffsetValue,

0 commit comments

Comments
 (0)