Skip to content

Commit e96481c

Browse files
committed
Remove NonEmptyArrayType after unset()
1 parent b290a73 commit e96481c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/Analyser/MutatingScope.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,7 +2879,8 @@ public function unsetExpression(Expr $expr): self
28792879
$nativeTypes
28802880
);
28812881
} elseif ($expr instanceof Expr\ArrayDimFetch && $expr->dim !== null) {
2882-
$constantArrays = TypeUtils::getConstantArrays($this->getType($expr->var));
2882+
$varType = $this->getType($expr->var);
2883+
$constantArrays = TypeUtils::getConstantArrays($varType);
28832884
if (count($constantArrays) > 0) {
28842885
$unsetArrays = [];
28852886
$dimType = $this->getType($expr->dim);
@@ -2894,7 +2895,13 @@ public function unsetExpression(Expr $expr): self
28942895

28952896
$args = [new Node\Arg($expr->var)];
28962897

2897-
return $this->invalidateExpression($expr->var)
2898+
$arrays = TypeUtils::getArrays($varType);
2899+
$scope = $this;
2900+
if (count($arrays) > 0) {
2901+
$scope = $scope->specifyExpressionType($expr->var, TypeCombinator::union(...$arrays));
2902+
}
2903+
2904+
return $scope->invalidateExpression($expr->var)
28982905
->invalidateExpression(new FuncCall(new Name\FullyQualified('count'), $args))
28992906
->invalidateExpression(new FuncCall(new Name('count'), $args));
29002907
}

0 commit comments

Comments
 (0)