Skip to content

Commit

Permalink
Merge pull request #8754 from orklah/#8041
Browse files Browse the repository at this point in the history
improve docs and phrasing about NoValue
  • Loading branch information
orklah committed Nov 25, 2022
2 parents a0e4468 + 2856ab1 commit b9a532d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
31 changes: 28 additions & 3 deletions docs/running_psalm/issues/NoValue.md
@@ -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
```
Expand Up @@ -530,7 +530,7 @@ public static function analyze(
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()
Expand Down
Expand Up @@ -810,7 +810,7 @@ public static function verifyType(
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()
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php
Expand Up @@ -177,7 +177,7 @@ public static function analyze(
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()
Expand Down

0 comments on commit b9a532d

Please sign in to comment.