Skip to content

Commit acee25b

Browse files
committed
fix callables
1 parent 4a7b4bc commit acee25b

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5180,6 +5180,8 @@ private function processArgs(
51805180
}
51815181
$throwPoints = array_merge($throwPoints, $callableThrowPoints);
51825182
$impurePoints = array_merge($impurePoints, array_map(static fn (SimpleImpurePoint $impurePoint) => new ImpurePoint($scope, $arg->value, $impurePoint->getIdentifier(), $impurePoint->getDescription(), $impurePoint->isCertain()), $acceptors[0]->getImpurePoints()));
5183+
$returnType = $acceptors[0]->getReturnType();
5184+
$isAlwaysTerminating = $isAlwaysTerminating || ($returnType instanceof NeverType && $returnType->isExplicit());
51835185
}
51845186
}
51855187
}

tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ public function testBug13232a(): void
269269
'Unreachable statement - code above always terminates.',
270270
23,
271271
],
272+
[
273+
'Unreachable statement - code above always terminates.',
274+
32,
275+
],
272276
]);
273277
}
274278

tests/PHPStan/Rules/DeadCode/data/bug-13232a.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ public function sayHo(): void
2323
echo 'this will never happen';
2424
}
2525

26+
public function sayHe(): void
27+
{
28+
$callable = function (): never {
29+
exit();
30+
};
31+
echo sprintf("Hello, %s no way", $callable);
32+
echo 'this will never happen';
33+
}
34+
35+
2636
function neverReturnsMethod(): never {
2737
exit();
2838
}

0 commit comments

Comments
 (0)