Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatchExpressionArmBody #1726

Merged
merged 3 commits into from Oct 19, 2022
Merged

MatchExpressionArmBody #1726

merged 3 commits into from Oct 19, 2022

Conversation

janedbal
Copy link
Contributor

No description provided.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically in both cases we should use the scope that's used in processExprNode when processsing the body expr. It's quite intuitive actually :)

@@ -2633,7 +2635,8 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
$filteringExpr = new BinaryOp\BooleanOr($filteringExpr, $armCondExpr);
}

$armNodes[] = new MatchExpressionArm($condNodes, $arm->getLine());
$matchArmBody = new MatchExpressionArmBody($armCondScope, $arm->body);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the correct scope here is the one that's created below in processExprNode call - $matchScope->filterByTruthyValue($filteringExpr) but please test that :)

@@ -2603,7 +2604,8 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
$hasYield = $hasYield || $armResult->hasYield();
$throwPoints = array_merge($throwPoints, $armResult->getThrowPoints());
$scope = $scope->mergeWith($matchScope);
$armNodes[] = new MatchExpressionArm([], $arm->getLine());
$matchArmBody = new MatchExpressionArmBody($scope, $arm->body);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the right scope here is $matchScope. But the one that's correct at the beginning of the foreach, before it's rewritten with $matchScope = $armResult->getScope();.

@ondrejmirtes ondrejmirtes merged commit 6ddf21b into phpstan:1.8.x Oct 19, 2022
@ondrejmirtes
Copy link
Member

I fixed the issues and merged this. Consider it a gift to your newborn 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants