Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4334,7 +4334,9 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
ExpressionContext::createTopLevel(),
);
$armScope = $armResult->getScope();
$armBodyScopes[] = $armScope;
if (!$armResult->isAlwaysTerminating()) {
$armBodyScopes[] = $armScope;
}
$hasYield = $hasYield || $armResult->hasYield();
$throwPoints = array_merge($throwPoints, $armResult->getThrowPoints());
$impurePoints = array_merge($impurePoints, $armResult->getImpurePoints());
Expand Down Expand Up @@ -4371,7 +4373,9 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
$hasYield = $hasYield || $armResult->hasYield();
$throwPoints = array_merge($throwPoints, $armResult->getThrowPoints());
$impurePoints = array_merge($impurePoints, $armResult->getImpurePoints());
$armBodyScopes[] = $matchScope;
if (!$armResult->isAlwaysTerminating()) {
$armBodyScopes[] = $matchScope;
}
continue;
}

Expand Down Expand Up @@ -4415,7 +4419,9 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
ExpressionContext::createTopLevel(),
);
$armScope = $armResult->getScope();
$armBodyScopes[] = $armScope;
if (!$armResult->isAlwaysTerminating()) {
$armBodyScopes[] = $armScope;
}
$hasYield = $hasYield || $armResult->hasYield();
$throwPoints = array_merge($throwPoints, $armResult->getThrowPoints());
$impurePoints = array_merge($impurePoints, $armResult->getImpurePoints());
Expand Down Expand Up @@ -4476,7 +4482,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
$result = $this->processExprNode($stmt, $expr->expr, $scope, $storage, $nodeCallback, ExpressionContext::createDeep());
$throwPoints = $result->getThrowPoints();
$impurePoints = $result->getImpurePoints();
$isAlwaysTerminating = $result->isAlwaysTerminating();
$isAlwaysTerminating = true;
$throwPoints[] = InternalThrowPoint::createExplicit($scope, $scope->getType($expr->expr), $expr, false);
} elseif ($expr instanceof FunctionCallableNode) {
$throwPoints = [];
Expand Down
31 changes: 31 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-9601.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug9601;

use function PHPStan\Testing\assertType;

class HelloWorld
{
public string $message = '';
}

class HelloWorld2
{
public string $message = '';
}

/**
* @param mixed $object
*/
function test($object): void
{
$objectName = match (true) {
$object instanceof HelloWorld => $object::class,
$object instanceof HelloWorld2 => $object::class,
default => throw new \LogicException(),
};

assertType('Bug9601\HelloWorld|Bug9601\HelloWorld2', $object);
}
8 changes: 0 additions & 8 deletions tests/PHPStan/Rules/ScopeFunctionCallStackRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ public function testRule(): void
"var_dump\nprint_r\nsleep",
7,
],
[
"var_dump\nprint_r\nsleep",
10,
],
[
"var_dump\nprint_r\nsleep",
13,
],
[
'ScopeFunctionCallStack\NamedArgumentTest::testMethod',
31,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ public function testRule(): void
"var_dump (\$value)\nprint_r (\$value)\nsleep (\$seconds)",
7,
],
[
"var_dump (\$value)\nprint_r (\$value)\nsleep (\$seconds)",
10,
],
[
"var_dump (\$value)\nprint_r (\$value)\nsleep (\$seconds)",
13,
],
[
// Named argument test - should report $notImmediate, not $immediate
'ScopeFunctionCallStack\NamedArgumentTest::testMethod ($notImmediate)',
Expand Down
Loading