-
Notifications
You must be signed in to change notification settings - Fork 669
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
InvalidReturnStatement for lists with shape inferred from PHP code with conditions #8942
Comments
I found these snippets: https://psalm.dev/r/c1147fc79d<?php
/** @return non-empty-list<string> */
function buildListWithOptionalValues(): array {
$list = [];
$entropy = random_int(0, 2);
if ($entropy === 0) {
$list[] = 'A';
} elseif ($entropy === 1) {
$list[] = 'B';
}
$list[] = 'C';
return $list;
}
buildListWithOptionalValues();
|
I've already started work to fix this and a number of other issues, it's a bit tricky :) |
Not sure if it is worth handling this. Even if https://psalm.dev/r/2c3fa92ffa Or I am misinterpreting something here. Maybe. Just stumbled upon this and was confused. |
I found these snippets: https://psalm.dev/r/2c3fa92ffa<?php
/** @return list<string> */
function createListWithTwoStringElements(): array
{
return ['foo', 'bar'];
}
/** @return array{0:string,1:string} */
function createArrayWithTwoStringElements(): array
{
return [
1 => 'bar',
0 => 'foo',
];
}
var_dump(array_is_list(createListWithTwoStringElements()), array_is_list(createArrayWithTwoStringElements()));
|
|
Fixed! |
Psalm: 5.3.0
list<string>
should be a superset oflist{0?: string, 1: string}
.https://psalm.dev/r/c1147fc79d
The text was updated successfully, but these errors were encountered: