Skip to content

Commit 90e49f7

Browse files
committed
Match expression - do not complain about void in arm body
1 parent 436143c commit 90e49f7

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,7 @@ static function () use ($finalScope, $expr): MutatingScope {
24922492
$armNodes = [];
24932493
foreach ($expr->arms as $arm) {
24942494
if ($arm->conds === null) {
2495-
$armResult = $this->processExprNode($arm->body, $matchScope, $nodeCallback, $deepContext);
2495+
$armResult = $this->processExprNode($arm->body, $matchScope, $nodeCallback, ExpressionContext::createTopLevel());
24962496
$matchScope = $armResult->getScope();
24972497
$hasYield = $hasYield || $armResult->hasYield();
24982498
$throwPoints = array_merge($throwPoints, $armResult->getThrowPoints());
@@ -2529,7 +2529,7 @@ static function () use ($finalScope, $expr): MutatingScope {
25292529
$arm->body,
25302530
$matchScope->filterByTruthyValue($filteringExpr),
25312531
$nodeCallback,
2532-
$deepContext
2532+
ExpressionContext::createTopLevel()
25332533
);
25342534
$armScope = $armResult->getScope();
25352535
$scope = $scope->mergeWith($armScope);

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,10 +1564,6 @@ public function testMatchExpressionVoidIsUsed(): void
15641564
'Result of method MatchExprVoidUsed\Foo::doBar() (void) is used.',
15651565
11,
15661566
],
1567-
[
1568-
'Result of method MatchExprVoidUsed\Foo::doBaz() (void) is used.',
1569-
11,
1570-
],
15711567
]);
15721568
}
15731569

tests/PHPStan/Rules/Methods/data/match-expr-void-used.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public function doFoo($m): void
99
{
1010
match ($this->doLorem()) {
1111
$this->doBar() => $this->doBaz(),
12+
default => $this->doBaz(),
1213
};
1314
}
1415

0 commit comments

Comments
 (0)