Skip to content

Commit a9f7b7b

Browse files
phpstan-botclaude
authored andcommitted
Allow stored expression types for new-chain expressions when set on the same AST node
When an expression has `new` in its receiver chain, only skip the stored type lookup if the stored type came from a different AST node (e.g. assert narrowing). If the stored type was set for the same AST node (e.g. inline @var annotation), allow it through. This fixes @var overrides on expressions like `return (new Defaults())->getFunctions()`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 593d589 commit a9f7b7b

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/Analyser/MutatingScope.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,8 @@ private function resolveType(string $exprString, Expr $node): Type
973973
!$node instanceof Variable
974974
&& !$node instanceof Expr\Closure
975975
&& !$node instanceof Expr\ArrowFunction
976-
&& !$this->expressionHasNewInChain($node)
977976
&& $this->hasExpressionType($node)->yes()
977+
&& (!$this->expressionHasNewInChain($node) || $this->expressionTypes[$exprString]->getExpr() === $node)
978978
) {
979979
return $this->expressionTypes[$exprString]->getType();
980980
}

0 commit comments

Comments
 (0)