Skip to content

Inferred result of array_pad() could be narrowed #12305

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

Open
rarila opened this issue Dec 20, 2024 · 0 comments · May be fixed by phpstan/phpstan-src#4017
Open

Inferred result of array_pad() could be narrowed #12305

rarila opened this issue Dec 20, 2024 · 0 comments · May be fixed by phpstan/phpstan-src#4017

Comments

@rarila
Copy link

rarila commented Dec 20, 2024

Feature request

It would be nice, if the inferred type of

array_pad(list<string>, int, <string>)

was list<string> instead of just array.

Code snippet:

https://phpstan.org/r/4ea29c2e-2200-4b09-bd7f-ee631736f6fc

Even more general the following could be inferred:

array_pad(list<TypeA>, int, <TypeB>)
    => list<TypeA|TypeB>
array_pad(array<TypeA>, int, <TypeB>)
    => array<array-key, TypeA|TypeB>
array_pad(non-empty-list<TypeA>, int<1, max>, <TypeB>)
   => non-empty-list<TypeA|TypeB>
array_pad(non-empty-array<TypeA>, int<1, max>, <TypeB>)
   => non-empty-array<array-key, TypeA|TypeB>
array_pad(list<TypeA>, int<1, max>, <TypeB>)
   => non-empty-list<TypeA|TypeB>
array_pad(array<TypeA>, int<1, max>, <TypeB>)
  => non-empty-array<array-key, TypeA|TypeB>

Did PHPStan help you today? Did it make you happy in any way?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants