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

Fix filter return provider #31

Merged
merged 4 commits into from
Jun 2, 2021
Merged

Fix filter return provider #31

merged 4 commits into from
Jun 2, 2021

Conversation

klimick
Copy link
Contributor

@klimick klimick commented Jun 2, 2021

Currently $result infers to array<int, int>:

/** @var $numbers list<int|null> */
$numbers = [1, 2, null];
$result = filter($numbers, fn(int|null $n) => null !== $n)

But return type should be list<int> (because preserveKeys false by default)

Furthermore. In this case, $result infers to array<string|int, int>:

/** @var $numbers list<int|null> */
$numbers = [1, 2, null];
$result = filter($numbers, fn(int|null $n) => null !== $n, preserveKeys: (bool) rand(0, 1))

But should be array<int, int> (not list<int> because we cannot be sure about preserveKeys value).

PR fixes errors from above.

@whsv26 whsv26 merged commit fb125bc into fp4php:master Jun 2, 2021
@klimick klimick deleted the fix-filter-return-provider branch September 7, 2021 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants