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

list does not contain iterable #3605

Closed
zerkms opened this issue Jun 18, 2020 · 3 comments
Closed

list does not contain iterable #3605

zerkms opened this issue Jun 18, 2020 · 3 comments
Labels

Comments

@zerkms
Copy link
Contributor

zerkms commented Jun 18, 2020

https://psalm.dev/r/d1a18e0d8d

This is a valid and logical php: you get keys and you check all of them are strings.

I believe after the line 16 the $keys should be narrowed to either list<string> or iterable<string>.

Yet it does not.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/d1a18e0d8d
<?php

    /**
     * @psalm-pure
     * @psalm-assert iterable<string> $value
     *
     * @param mixed  $value
     * @param string $message
     *
     * @throws InvalidArgumentException
     */
    function allString($value, $message = ''): void {}

function takesAnArray(array $a): void {
    $keys = array_keys($a);
    allString($keys);
}
Psalm output (using commit 21e5678):

INFO: UnusedParam - 12:24 - Param $value is never referenced in this method

INFO: UnusedParam - 12:32 - Param $message is never referenced in this method

ERROR: DocblockTypeContradiction - 16:5 - Cannot resolve types for $keys - docblock-defined type list<array-key> does not contain iterable<mixed, string>

@Great-Antique
Copy link

Great-Antique commented Jun 18, 2020

Another example: https://psalm.dev/r/15c5758fe5

If you change order of asserts then you'll get reversed error which is fine as standalone check but in this case I make two checks and resulting assert must take this into account

docblock-defined type iterable<mixed, non-empty-string> does not contain list<string>

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/15c5758fe5
<?php

/**
* @param mixed $a
* @psalm-assert list<string> $a
*/
function listOfStrings($a): void {}

/**
* @param mixed $a
* @psalm-assert iterable<non-empty-string> $a
*/
function allStringNotEmpty($a): void {}

/**
* @param mixed $a
* @psalm-assert list<non-empty-string> $a
*/
function listOfNotEmptyStrings($a): void {
	listOfStrings($a);
    allStringNotEmpty($a);
}

listOfNotEmptyStrings(['asd', '']);
Psalm output (using commit 21e5678):

INFO: UnusedParam - 7:24 - Param $a is never referenced in this method

INFO: UnusedParam - 13:28 - Param $a is never referenced in this method

ERROR: DocblockTypeContradiction - 21:5 - Cannot resolve types for $a - docblock-defined type list<string> does not contain iterable<mixed, non-empty-string>

@weirdan weirdan added the bug label Jun 18, 2020
@muglug muglug closed this as completed in 9862278 Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants