Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.10.x' into 1.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 11, 2024
2 parents a8c5263 + ff0c201 commit 9c4508d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -1526,17 +1526,20 @@ private function resolveType(string $exprString, Expr $node): Type
);
}

$filteringExprType = $matchScope->getType($filteringExpr);
$noopCallback = static function (): void {
};
$filteringExprResult = $this->nodeScopeResolver->processExprNode(new Node\Stmt\Expression($filteringExpr), $filteringExpr, $matchScope, $noopCallback, ExpressionContext::createDeep());

$filteringExprType = $matchScope->getType($filteringExpr);
if (!$filteringExprType->isFalse()->yes()) {
$truthyScope = $matchScope->filterByTruthyValue($filteringExpr);
$truthyScope = $filteringExprResult->getTruthyScope();
if ($node->hasAttribute(self::KEEP_VOID_ATTRIBUTE_NAME)) {
$arm->body->setAttribute(self::KEEP_VOID_ATTRIBUTE_NAME, $node->getAttribute(self::KEEP_VOID_ATTRIBUTE_NAME));
}
$types[] = $truthyScope->getType($arm->body);
}

$matchScope = $matchScope->filterByFalseyValue($filteringExpr);
$matchScope = $filteringExprResult->getFalseyScope();
}

return TypeCombinator::union(...$types);
Expand Down
11 changes: 6 additions & 5 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2884,23 +2884,24 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
);
}

$bodyScope = $this->processExprNode($stmt, $filteringExpr, $matchScope, static function (): void {
}, $deepContext)->getTruthyScope();
$matchArmBody = new MatchExpressionArmBody($bodyScope, $arm->body);
$filteringExprResult = $this->processExprNode($stmt, $filteringExpr, $matchScope, static function (): void {
}, $deepContext);
$truthyScope = $filteringExprResult->getTruthyScope();
$matchArmBody = new MatchExpressionArmBody($truthyScope, $arm->body);
$armNodes[] = new MatchExpressionArm($matchArmBody, $condNodes, $arm->getStartLine());

$armResult = $this->processExprNode(
$stmt,
$arm->body,
$bodyScope,
$truthyScope,
$nodeCallback,
ExpressionContext::createTopLevel(),
);
$armScope = $armResult->getScope();
$scope = $scope->mergeWith($armScope);
$hasYield = $hasYield || $armResult->hasYield();
$throwPoints = array_merge($throwPoints, $armResult->getThrowPoints());
$matchScope = $matchScope->filterByFalseyValue($filteringExpr);
$matchScope = $filteringExprResult->getFalseyScope();
}

$remainingType = $matchScope->getType($expr->cond);
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Variables/data/bug-10418.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types = 1);
<?php declare(strict_types = 1); // lint >= 8.1

namespace Bug10418;

Expand Down

0 comments on commit 9c4508d

Please sign in to comment.