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

improve docs and phrasing about NoValue

This commit is contained in:
orklah 2022-11-24 20:49:34 +01:00
parent 8f39de9001
commit 4d358c4be9
4 changed files with 22 additions and 6 deletions

View File

@ -1,16 +1,32 @@
# NoValue
Emitted when using the result of a function that never returns.
Emitted when Psalm invalidated all possible types for a given expression
```php
<?php
/**
* @return never-returns
* @return never
*/
function foo() : void {
exit();
}
$a = foo();
$a = foo(); // Psalm knows $a will never contain any type because foo() won't return
```
```php
<?php
function foo() : void {
return throw new Exception(''); //Psalm detected the return expression is never used
}
```
```php
<?php
function shutdown(): never {die('Application closed unexpectedly');}
function foo(string $_a): void{}
foo(shutdown()); // foo() will never be called
```

View File

@ -530,7 +530,7 @@ class AssignmentAnalyzer
if ($context->vars_in_scope[$var_id]->isNever()) {
if (IssueBuffer::accepts(
new NoValue(
'This function or method call never returns output',
'All possible type for this assignment were invalidated - This may be dead code',
new CodeLocation($statements_analyzer->getSource(), $assign_var)
),
$statements_analyzer->getSuppressedIssues()

View File

@ -810,7 +810,7 @@ class ArgumentAnalyzer
if ($input_type->isNever()) {
IssueBuffer::maybeAdd(
new NoValue(
'This function or method call never returns output',
'All possible types for this argument were invalidated - This may be dead code',
$arg_location
),
$statements_analyzer->getSuppressedIssues()

View File

@ -177,7 +177,7 @@ class ReturnAnalyzer
if ($stmt_type->isNever()) {
IssueBuffer::maybeAdd(
new NoValue(
'This function or method call never returns output',
'All possible types for this return were invalidated - This may be dead code',
new CodeLocation($source, $stmt)
),
$statements_analyzer->getSuppressedIssues()