Skip to content

Commit d87b3a5

Browse files
committed
More match fixes
1 parent 2b74aa8 commit d87b3a5

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/Analyser/MutatingScope.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,17 +1526,20 @@ private function resolveType(string $exprString, Expr $node): Type
15261526
);
15271527
}
15281528

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

1533+
$filteringExprType = $matchScope->getType($filteringExpr);
15311534
if (!$filteringExprType->isFalse()->yes()) {
1532-
$truthyScope = $matchScope->filterByTruthyValue($filteringExpr);
1535+
$truthyScope = $filteringExprResult->getTruthyScope();
15331536
if ($node->hasAttribute(self::KEEP_VOID_ATTRIBUTE_NAME)) {
15341537
$arm->body->setAttribute(self::KEEP_VOID_ATTRIBUTE_NAME, $node->getAttribute(self::KEEP_VOID_ATTRIBUTE_NAME));
15351538
}
15361539
$types[] = $truthyScope->getType($arm->body);
15371540
}
15381541

1539-
$matchScope = $matchScope->filterByFalseyValue($filteringExpr);
1542+
$matchScope = $filteringExprResult->getFalseyScope();
15401543
}
15411544

15421545
return TypeCombinator::union(...$types);

src/Analyser/NodeScopeResolver.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,23 +2884,24 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
28842884
);
28852885
}
28862886

2887-
$bodyScope = $this->processExprNode($stmt, $filteringExpr, $matchScope, static function (): void {
2888-
}, $deepContext)->getTruthyScope();
2889-
$matchArmBody = new MatchExpressionArmBody($bodyScope, $arm->body);
2887+
$filteringExprResult = $this->processExprNode($stmt, $filteringExpr, $matchScope, static function (): void {
2888+
}, $deepContext);
2889+
$truthyScope = $filteringExprResult->getTruthyScope();
2890+
$matchArmBody = new MatchExpressionArmBody($truthyScope, $arm->body);
28902891
$armNodes[] = new MatchExpressionArm($matchArmBody, $condNodes, $arm->getLine());
28912892

28922893
$armResult = $this->processExprNode(
28932894
$stmt,
28942895
$arm->body,
2895-
$bodyScope,
2896+
$truthyScope,
28962897
$nodeCallback,
28972898
ExpressionContext::createTopLevel(),
28982899
);
28992900
$armScope = $armResult->getScope();
29002901
$scope = $scope->mergeWith($armScope);
29012902
$hasYield = $hasYield || $armResult->hasYield();
29022903
$throwPoints = array_merge($throwPoints, $armResult->getThrowPoints());
2903-
$matchScope = $matchScope->filterByFalseyValue($filteringExpr);
2904+
$matchScope = $filteringExprResult->getFalseyScope();
29042905
}
29052906

29062907
$remainingType = $matchScope->getType($expr->cond);

0 commit comments

Comments
 (0)