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

Merge pull request #8754 from orklah/#8041

improve docs and phrasing about NoValue
This commit is contained in:
orklah 2022-11-25 20:18:40 +01:00 committed by GitHub
commit b9a532db26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 6 deletions

View File

@ -1,16 +1,41 @@
# NoValue
Emitted when using the result of a function that never returns.
Emitted when Psalm invalidated all possible types for a given expression. It is often an indication that Psalm found dead code or that documented types were not exhaustive
```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
```
```php
<?php
$a = [];
/** @psalm-suppress TypeDoesNotContainType */
assert(!empty($a));
count($a); // Assert above always fail. There is no possible type that $a can have here
```

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 types 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()