Skip to content

Commit

Permalink
specify expression even it doesn't change types
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan committed May 12, 2022
1 parent 9381526 commit c0bf915
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -4174,8 +4174,21 @@ public function specifyExpressionType(Expr $expr, Type $type, ?Type $nativeType
if (count($constantArrays) > 0) {
$setArrays = [];
$dimType = $this->getType($expr->dim);
if ($dimType instanceof UnionType) {
$dimTypes = $dimType->getTypes();
} else {
$dimTypes = [$dimType];
}
foreach ($constantArrays as $constantArray) {
$setArrays[] = $constantArray->setOffsetValueType($dimType, $type);
foreach ($dimTypes as $innerType) {
if ($constantArray->hasOffsetValueType($innerType)->no()) {
continue;
}
$setArrays[] = $constantArray->setOffsetValueType(
TypeCombinator::intersect(ArrayType::castToArrayKeyType($innerType), $constantArray->getKeyType()),
$dimType instanceof UnionType ? TypeCombinator::intersect($type, $constantArray->getOffsetValueType($innerType)) : $type,
);
}
}
$scope = $this->specifyExpressionType(
$expr->var,
Expand Down Expand Up @@ -4351,15 +4364,13 @@ public function invalidateMethodsOnExpression(Expr $expressionToInvalidate): sel
public function removeTypeFromExpression(Expr $expr, Type $typeToRemove): self
{
$exprType = $this->getType($expr);
$typeAfterRemove = TypeCombinator::remove($exprType, $typeToRemove);
if (
!$expr instanceof Variable
&& $exprType->equals($typeAfterRemove)
&& !$exprType instanceof ErrorType
&& !$exprType instanceof NeverType
$exprType instanceof NeverType ||
$typeToRemove instanceof NeverType
) {
return $this;
}
$typeAfterRemove = TypeCombinator::remove($exprType, $typeToRemove);
$scope = $this->specifyExpressionType(
$expr,
$typeAfterRemove,
Expand Down

0 comments on commit c0bf915

Please sign in to comment.