Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/Analyser/ExprHandler/MethodCallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
if ($parametersAcceptor !== null) {
$normalizedExpr = ArgumentsNormalizer::reorderMethodArguments($parametersAcceptor, $expr) ?? $expr;
$returnType = $parametersAcceptor->getReturnType();
$isAlwaysTerminating = $returnType instanceof NeverType && $returnType->isExplicit();
$isAlwaysTerminating = $isAlwaysTerminating || ($returnType instanceof NeverType && $returnType->isExplicit());
}

$argsResult = $nodeScopeResolver->processArgs(
Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/ExprHandler/StaticCallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
if ($parametersAcceptor !== null) {
$normalizedExpr = ArgumentsNormalizer::reorderStaticCallArguments($parametersAcceptor, $expr) ?? $expr;
$returnType = $parametersAcceptor->getReturnType();
$isAlwaysTerminating = $returnType instanceof NeverType && $returnType->isExplicit();
$isAlwaysTerminating = $isAlwaysTerminating || ($returnType instanceof NeverType && $returnType->isExplicit());
Comment thread
staabm marked this conversation as resolved.
}
$argsResult = $nodeScopeResolver->processArgs($stmt, $methodReflection, null, $parametersAcceptor, $normalizedExpr, $scope, $storage, $nodeCallback, $context, $closureBindScope);
$scope = $argsResult->getScope();
Expand Down
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,16 @@ public function testBug13331(): void
$this->analyse([__DIR__ . '/data/bug-13331.php'], []);
}

#[RequiresPhp('>= 8.2')]
public function testBug14328(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-14328.php'], [
[
'Unreachable statement - code above always terminates.',
16,
],
]);
}

}
16 changes: 16 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/bug-14328.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php // lint >= 8.2

declare(strict_types = 1);

namespace Bug14328;

$callback = fn (): never => throw new \Exception();

class Foo {
public function returnThis(mixed $value): self {
return $this;
}
}

$x = (new Foo())->returnThis($callback())->returnThis('x');
$y = 'this will never run';
Loading