Skip to content

Commit fc62b0a

Browse files
Bug 9601
1 parent 66617b9 commit fc62b0a

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/Analyser/ExprHandler/MatchHandler.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
335335
ExpressionContext::createTopLevel(),
336336
);
337337
$armScope = $armResult->getScope();
338-
$armBodyScopes[] = $armScope;
338+
if (!$armResult->isAlwaysTerminating()) {
339+
$armBodyScopes[] = $armScope;
340+
}
339341
$hasYield = $hasYield || $armResult->hasYield();
340342
$throwPoints = array_merge($throwPoints, $armResult->getThrowPoints());
341343
$impurePoints = array_merge($impurePoints, $armResult->getImpurePoints());
@@ -372,7 +374,9 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
372374
$hasYield = $hasYield || $armResult->hasYield();
373375
$throwPoints = array_merge($throwPoints, $armResult->getThrowPoints());
374376
$impurePoints = array_merge($impurePoints, $armResult->getImpurePoints());
375-
$armBodyScopes[] = $matchScope;
377+
if (!$armResult->isAlwaysTerminating()) {
378+
$armBodyScopes[] = $matchScope;
379+
}
376380
continue;
377381
}
378382

@@ -423,7 +427,9 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
423427
ExpressionContext::createTopLevel(),
424428
);
425429
$armScope = $armResult->getScope();
426-
$armBodyScopes[] = $armScope;
430+
if (!$armResult->isAlwaysTerminating()) {
431+
$armBodyScopes[] = $armScope;
432+
}
427433
$hasYield = $hasYield || $armResult->hasYield();
428434
$throwPoints = array_merge($throwPoints, $armResult->getThrowPoints());
429435
$impurePoints = array_merge($impurePoints, $armResult->getImpurePoints());
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php // lint >= 8.0
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug9601;
6+
7+
use function PHPStan\Testing\assertType;
8+
9+
class HelloWorld
10+
{
11+
public string $message = '';
12+
}
13+
14+
class HelloWorld2
15+
{
16+
public string $message = '';
17+
}
18+
19+
/**
20+
* @param mixed $object
21+
*/
22+
function test($object): void
23+
{
24+
$objectName = match (true) {
25+
$object instanceof HelloWorld => $object::class,
26+
$object instanceof HelloWorld2 => $object::class,
27+
default => throw new \LogicException(),
28+
};
29+
30+
assertType('Bug9601\HelloWorld|Bug9601\HelloWorld2', $object);
31+
}

0 commit comments

Comments
 (0)