Skip to content

Commit

Permalink
Merge pull request #6828 from orklah/function-un-unevaluated
Browse files Browse the repository at this point in the history
allow declaring functions and classLikes after a never-returning call
  • Loading branch information
orklah authored Nov 5, 2021
2 parents 9651daf + f4f9bd6 commit 603fa65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ private static function analyzeStatement(
&& !$context->collect_mutations
&& !($stmt instanceof PhpParser\Node\Stmt\Nop)
&& !($stmt instanceof PhpParser\Node\Stmt\InlineHTML)
&& !($stmt instanceof PhpParser\Node\Stmt\Function_)
&& !($stmt instanceof PhpParser\Node\Stmt\Class_)
&& !($stmt instanceof PhpParser\Node\Stmt\Interface_)
&& !($stmt instanceof PhpParser\Node\Stmt\Trait_)
) {
if ($codebase->find_unused_variables) {
if (IssueBuffer::accepts(
Expand Down
13 changes: 13 additions & 0 deletions tests/UnusedCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,19 @@ function f(): int
`$used`;
',
],
'notUnevaluatedFunction' => [
'<?php
/** @return never */
function neverReturns(){
die();
}
unrelated();
neverReturns();
function unrelated():void{
echo "hello";
}',
],
];
}

Expand Down

0 comments on commit 603fa65

Please sign in to comment.