You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrectly inferred return type for Psl\Iter\first(...) #12
Describe the bug
When provided an array with type list<string>, the output of Psl\Iter\first($array) is considered by the plugin's FunctionReturnTypeProvider to be never null, which is presumably not true.
To Reproduce
Run Psalm with this plugin enabled on the following code:
/** @var list<string> $series **/$series = ['val1', 'val2'];
$firstInSeries = \Psl\Iter\first($series);
\assert($firstInSeries !== null); // assert with any assertion module you like, it's a similar output for all.
Output:
ERROR: RedundantConditionGivenDocblockType - ../../test.php:32:9 - Docblock-defined type string can never contain null (see https://psalm.dev/156)
\assert($firstInSeries !== null);
When duplicating the code of \Psl\Iter\first so that the plugin is not applied, this problem does not occur:
Activity
azjezz commentedon Jan 25, 2023
this shouldn't really happen unless the type is known not to be empty ( https://github.com/php-standard-library/psalm-plugin/blob/main/src/EventHandler/Iter/First/FunctionReturnTypeProvider.php#L36-L42 ), i will look further into it 👍