Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve docs and phrasing about NoValue #8754

Merged
merged 4 commits into from Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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