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:
parent
2b4b55fd33
commit
cca0070d38
@ -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)
|
||||
) {
|
||||
|
@ -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
|
||||
|
@ -568,6 +568,22 @@ class ReturnTypeTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'noReturnCallReturns' => [
|
||||
'<?php
|
||||
/**
|
||||
* @return never-returns
|
||||
*/
|
||||
function foo() : void {
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return never-returns
|
||||
*/
|
||||
function bar() : void {
|
||||
foo();
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user