Skip to content

Commit 38dbc55

Browse files
phpstan-botclaude
authored andcommitted
Avoid setAlwaysOverwriteTypes() in specifyOnly statement path
Replace the SpecifiedTypes + setAlwaysOverwriteTypes() construction with a direct assignExpression() call, which is what the overwrite branch of filterBySpecifiedTypes() does internally. Functionally identical, but avoids the bug-prone setAlwaysOverwriteTypes() flag. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent cfbf413 commit 38dbc55

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

‎src/Analyser/NodeScopeResolver.php‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,14 +1153,9 @@ public function processStmtNode(
11531153
if ($specifiedTypes->shouldSpecifyOnly()) {
11541154
// Statement counterpart of the specifyOnly handling in filterByTruthyValue():
11551155
// store the call's true result so a duplicate void assertion statement is
1156-
// reported as always-true. We overwrite directly (not via TypeSpecifier::create)
1157-
// because void calls have no return value to protect from the purity check.
1158-
$scope = $scope->filterBySpecifiedTypes(
1159-
(new SpecifiedTypes(
1160-
[$scope->getNodeKey($stmt->expr) => [$stmt->expr, new ConstantBooleanType(true)]],
1161-
[],
1162-
))->setAlwaysOverwriteTypes(),
1163-
);
1156+
// reported as always-true. We assign directly because void calls have no
1157+
// return value to protect, and intersecting true with void would produce never.
1158+
$scope = $scope->assignExpression($stmt->expr, new ConstantBooleanType(true), new ConstantBooleanType(true));
11641159
}
11651160
$hasYield = $result->hasYield();
11661161
$throwPoints = $result->getThrowPoints();

0 commit comments

Comments
 (0)