1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Allow function calls that exit to act themselves like exit

This commit is contained in:
Brown 2019-01-02 17:16:04 -05:00
parent 2b4b55fd33
commit cca0070d38
3 changed files with 30 additions and 2 deletions

View File

@ -54,12 +54,16 @@ class ReturnTypeCollector
}
break;
} elseif ($stmt instanceof PhpParser\Node\Stmt\Throw_
}
if ($stmt instanceof PhpParser\Node\Stmt\Throw_
|| $stmt instanceof PhpParser\Node\Stmt\Break_
|| $stmt instanceof PhpParser\Node\Stmt\Continue_
) {
break;
} elseif ($stmt instanceof PhpParser\Node\Stmt\Expression
}
if ($stmt instanceof PhpParser\Node\Stmt\Expression
&& ($stmt->expr instanceof PhpParser\Node\Expr\Yield_
|| $stmt->expr instanceof PhpParser\Node\Expr\YieldFrom)
) {

View File

@ -100,6 +100,14 @@ class ScopeAnalyzer
return [self::ACTION_END];
}
// This allows calls to functions that always exit to act as exit statements themselves
if (!$return_is_exit
&& isset($stmt->expr->inferredType)
&& $stmt->expr->inferredType->isNever()
) {
return [self::ACTION_END];
}
if ($exit_functions) {
if ($stmt->expr instanceof PhpParser\Node\Expr\FuncCall
|| $stmt->expr instanceof PhpParser\Node\Expr\StaticCall

View File

@ -568,6 +568,22 @@ class ReturnTypeTest extends TestCase
}
}',
],
'noReturnCallReturns' => [
'<?php
/**
* @return never-returns
*/
function foo() : void {
exit();
}
/**
* @return never-returns
*/
function bar() : void {
foo();
}',
],
];
}