psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Invalid type for SQLite3Result::columnName

Open stof opened this issue 1 year ago • 2 comments

https://psalm.dev/r/634c35d072

Psalm complains when comparing the return value to false. But the method can return false: https://www.php.net/manual/en/sqlite3result.columnname.php

stof avatar Jun 07 '24 11:06 stof

I found these snippets:

https://psalm.dev/r/634c35d072
<?php

function getColumnName(SQLite3Result $result, int $index): string {
    $name = $result->columnName($index);
    
    if ($name === false) {
        throw new \OutOfBoundsException("Invalid index $index.");
    }
    
    return $name;
}
Psalm output (using commit 16b24bd):

ERROR: TypeDoesNotContainType - 6:9 - string does not contain false

psalm-github-bot[bot] avatar Jun 07 '24 11:06 psalm-github-bot[bot]

This snippet shows how this method can return false: https://3v4l.org/0mQHi

derrabus avatar Jun 19 '24 07:06 derrabus