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

expects array<int>, array<int>|int<min, -1>|int<1, max> given #5749

Closed
voku opened this issue Oct 7, 2021 · 6 comments
Closed

expects array<int>, array<int>|int<min, -1>|int<1, max> given #5749

voku opened this issue Oct 7, 2021 · 6 comments
Labels

Comments

@voku
Copy link
Contributor

voku commented Oct 7, 2021

Bug report

array<int> should include array<int>, array<int>|int<min, -1>|int<1, max>

Code snippet that reproduces the problem

https://phpstan.org/r/3e6501a6-06a3-4394-b559-342550be708b

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

PHPStan is an excellent tool to increase the code quality step-by-step, I like it.

@ondrejmirtes ondrejmirtes added this to the Dependent types milestone Oct 7, 2021
@ondrejmirtes
Copy link
Member

Hi, this is very complicated code and it's hard to fix this scenario. It's not even obvious for me what should happen for 0 and [0]. Because to me it looks like that you'll accept and run self::dbarray_int($type) for [0] being passed into the method, but you'll set $typeSql to '' when 0 is passed into the method.

I think I wrote an equivalent code to yours that's much better understandable by PHPStan: https://phpstan.org/r/ba7ccf3e-6f9b-4920-b46c-056719ca3445

But still, I think you might have an unwanted bug on your hands.

@voku
Copy link
Contributor Author

voku commented Oct 7, 2021

Thanks for the answer. 💯 I first rewrote the code and allow only int[] as type for the "type" param, but I will use your code example because there is no breaking-change, thanks again.

@phpstan-bot
Copy link
Contributor

@voku After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-34: Parameter #1 $array of static method ActiveRowFactory::dbarray_int() expects array<int>, array<int>|int<min, -1>|int<1, max> given.
+34: Parameter #1 $array of static method ActiveRowFactory::dbarray_int() expects array<int>, array<int>|int|int given.
Full report
Line Error
34 `Parameter #1 $array of static method ActiveRowFactory::dbarray_int() expects array, array

@phpstan-bot
Copy link
Contributor

@voku After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-34: Parameter #1 $array of static method ActiveRowFactory::dbarray_int() expects array<int>, array<int>|int<min, -1>|int<1, max> given.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@cc6655f

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants