diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index a55a6dc7cd..5e2f28465e 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -3603,6 +3603,7 @@ public function assignExpression(Expr $expr, Type $type): self public function invalidateExpression(Expr $expressionToInvalidate, bool $requireMoreCharacters = false): self { $exprStringToInvalidate = $this->getNodeKey($expressionToInvalidate); + $expressionToInvalidateClass = get_class($expressionToInvalidate); $moreSpecificTypeHolders = $this->moreSpecificTypes; $nativeExpressionTypes = $this->nativeExpressionTypes; $invalidated = false; @@ -3618,11 +3619,8 @@ public function invalidateExpression(Expr $expressionToInvalidate, bool $require if (!$expr instanceof Node\Stmt\Expression) { throw new \PHPStan\ShouldNotHappenException(); } - $found = $nodeFinder->findFirst([$expr->expr], function (Node $node) use ($exprStringToInvalidate): bool { - if (!$node instanceof Expr) { - return false; - } - if ($node instanceof EncapsedStringPart) { + $found = $nodeFinder->findFirst([$expr->expr], function (Node $node) use ($expressionToInvalidateClass, $exprStringToInvalidate): bool { + if (!$node instanceof $expressionToInvalidateClass) { return false; }