Skip to content

Commit

Permalink
Fix removeTypeFromExpression()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 6, 2020
1 parent ce0bc46 commit 7747262
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -2866,14 +2866,22 @@ public function invalidateExpression(Expr $expressionToInvalidate, bool $require
);
}

public function removeTypeFromExpression(Expr $expr, Type $type): self
public function removeTypeFromExpression(Expr $expr, Type $typeToRemove): self
{
$exprType = $this->getType($expr);
$typeAfterRemove = TypeCombinator::remove($exprType, $typeToRemove);
if (
!$expr instanceof Variable
&& $exprType->equals($typeAfterRemove)
) {
return $this;
}
$scope = $this->specifyExpressionType(
$expr,
TypeCombinator::remove($this->getType($expr), $type)
$typeAfterRemove
);
if ($expr instanceof Variable && is_string($expr->name)) {
$scope->nativeExpressionTypes[sprintf('$%s', $expr->name)] = TypeCombinator::remove($this->getNativeType($expr), $type);
$scope->nativeExpressionTypes[sprintf('$%s', $expr->name)] = TypeCombinator::remove($this->getNativeType($expr), $typeToRemove);
}

return $scope;
Expand Down

0 comments on commit 7747262

Please sign in to comment.