1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00
psalm/docs/running_psalm/issues/NoValue.md
2022-11-24 20:56:49 +01:00

834 B

NoValue

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

/**
 * @return never
 */
function foo() : void {
    exit();
}

$a = foo(); // Psalm knows $a will never contain any type because foo() won't return
<?php

function foo() : void {
    return throw new Exception(''); //Psalm detected the return expression is never used
}
<?php
function shutdown(): never {die('Application closed unexpectedly');}
function foo(string $_a): void{}

foo(shutdown()); // foo() will never be called
<?php
$a = [];
/** @psalm-suppress TypeDoesNotContainType */
assert(!empty($a));

count($a); // Assert above always fail. There is no possible type that $a can have here