Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
improve docs and phrasing about NoValue
- Loading branch information
Showing
4 changed files
with
31 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters