Psalm: array_keys(non-empty-array) should return non-empty-list

Created on 16 Apr 2020  路  3Comments  路  Source: vimeo/psalm

All 3 comments

I found these snippets:


https://psalm.dev/r/110bc828f0

<?php

final class A
{
    /**
     * @psalm-var non-empty-array<string, string>
     */
    private array $nonEmptyArray = ['a' => 'b'];

    /**
     * @return non-empty-list<string>
     */
    public function getKeys(): array
    {
        return array_keys($this->nonEmptyArray);
    }
}
Psalm output (using commit 6f28ee6):

ERROR: InvalidReturnStatement - 15:16 - The inferred type 'list<string>' does not match the declared return type 'non-empty-list<string>' for A::getKeys

ERROR: InvalidReturnType - 11:16 - The declared return type 'non-empty-list<string>' for A::getKeys is incorrect, got 'list<string>'

Mind PRing this change? Should be simple enough

This is finally finally fixed

Was this page helpful?
0 / 5 - 0 ratings