Skip to content

Commit

Permalink
Avoid calling describe on ConstantArrayTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored and ondrejmirtes committed Apr 3, 2022
1 parent 6b6f310 commit 2c9273e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3088,7 +3088,7 @@ protected function getTypeFromArrayDimFetch(
throw new ShouldNotHappenException();
}

if ((new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes()) {
if (!$offsetAccessibleType->isArray()->yes() && (new ObjectType(ArrayAccess::class))->isSuperTypeOf($offsetAccessibleType)->yes()) {
return $this->getType(
new MethodCall(
$arrayDimFetch->var,
Expand Down
4 changes: 2 additions & 2 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3306,7 +3306,7 @@ private function processAssignVar(
$valueToWrite = $offsetValueType->setOffsetValueType($offsetType, $valueToWrite, $i === 0);
}

if (!(new ObjectType(ArrayAccess::class))->isSuperTypeOf($varType)->yes()) {
if ($varType->isArray()->yes() || !(new ObjectType(ArrayAccess::class))->isSuperTypeOf($varType)->yes()) {
if ($var instanceof Variable && is_string($var->name)) {
$scope = $scope->assignVariable($var->name, $valueToWrite);
} else {
Expand Down Expand Up @@ -3334,7 +3334,7 @@ private function processAssignVar(
}
}

if (!(new ObjectType(ArrayAccess::class))->isSuperTypeOf($varType)->no()) {
if (!$varType->isArray()->yes() && !(new ObjectType(ArrayAccess::class))->isSuperTypeOf($varType)->no()) {
$throwPoints = array_merge($throwPoints, $this->processExprNode(
new MethodCall($var, 'offsetSet'),
$scope,
Expand Down

0 comments on commit 2c9273e

Please sign in to comment.