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

array shapes are not taken into account to exclude incorrect combinations for false positives #6633

Closed
Kingdutch opened this issue Feb 11, 2022 · 6 comments

Comments

@Kingdutch
Copy link

Bug report

I was trying to do something a bit clever to re-use some boilerplate with different sets of values. The sets of values are stored in an array and they work together. However, PHPStan merges the array shapes and thus thinks the input argument is incorrect.

Parameter #1 $data of callable (Closure(CreateServiceSolrData): ServiceSolr)|(Closure(CreateServiceRedisData): ServiceRedis) expects CreateServiceSolrData, CreateServiceRedisData|CreateServiceSolrData given.

Code snippet that reproduces the problem

Here is the issue as array:
https://phpstan.org/r/7410fa9a-4b11-4926-acf7-0bf86200e3f3

I thought PHPStan may have been confused by the observability of the dynamic array access, so I moved to individual variables with a switch statement that could be validated as standalone objects/paths. However, it looks like PHPStan still merges the type-shapes under the hood causing issues.
https://phpstan.org/r/8429299b-505a-435d-a360-d3de75fcd66e

Expected output

No issues

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

Running PHPStan at level 9 helps me figure out if these kinds of shenanigans actually work :D

@Kingdutch
Copy link
Author

Kingdutch commented Feb 11, 2022

Changing it to functions also doesn't help: https://phpstan.org/r/fc02ccfe-c21d-4885-a38b-f1509f8ec1fa

Also forgot to note that this may be related to either #6364 or #3616

@phpstan-bot
Copy link
Contributor

@Kingdutch After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet:

@@ @@
 PHP 8.0 – 8.1 (1 error)
 ==========
 
-68: Parameter #1 $data of callable (Closure(CreateServiceSolrData): ServiceSolr)|(Closure(CreateServiceRedisData): ServiceRedis) expects CreateServiceSolrData, CreateServiceRedisData|CreateServiceSolrData given.
+68: Parameter #1 $data of callable (Closure(CreateServiceRedisData): ServiceRedis)|(Closure(CreateServiceSolrData): ServiceSolr) expects CreateServiceRedisData, CreateServiceRedisData|CreateServiceSolrData given.
 
 PHP 7.1 – 7.4 (3 errors)
 ==========
@@ @@
 
 19: Promoted properties are supported only on PHP 8.0 and later.
 31: Promoted properties are supported only on PHP 8.0 and later.
-68: Parameter #1 $data of callable (Closure(CreateServiceSolrData): ServiceSolr)|(Closure(CreateServiceRedisData): ServiceRedis) expects CreateServiceSolrData, CreateServiceRedisData|CreateServiceSolrData given.
+68: Parameter #1 $data of callable (Closure(CreateServiceRedisData): ServiceRedis)|(Closure(CreateServiceSolrData): ServiceSolr) expects CreateServiceRedisData, CreateServiceRedisData|CreateServiceSolrData given.
Full report

PHP 8.0 – 8.1 (1 error)

Line Error
68 `Parameter #1 $data of callable (Closure(CreateServiceRedisData): ServiceRedis)

PHP 7.1 – 7.4 (3 errors)

Line Error
19 Promoted properties are supported only on PHP 8.0 and later.
31 Promoted properties are supported only on PHP 8.0 and later.
68 `Parameter #1 $data of callable (Closure(CreateServiceRedisData): ServiceRedis)

@phpstan-bot
Copy link
Contributor

@Kingdutch After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet:

@@ @@
 PHP 8.0 – 8.1 (1 error)
 ==========
 
-77: Parameter #1 $data of callable (Closure(CreateServiceRedisData): ServiceRedis)|(Closure(CreateServiceSolrData): ServiceSolr) expects CreateServiceRedisData, CreateServiceRedisData|CreateServiceSolrData given.
+77: Parameter #1 $data of callable (Closure(CreateServiceSolrData): ServiceSolr)|(Closure(CreateServiceRedisData): ServiceRedis) expects CreateServiceSolrData, CreateServiceRedisData|CreateServiceSolrData given.
 
 PHP 7.1 – 7.4 (3 errors)
 ==========
@@ @@
 
 19: Promoted properties are supported only on PHP 8.0 and later.
 31: Promoted properties are supported only on PHP 8.0 and later.
-77: Parameter #1 $data of callable (Closure(CreateServiceRedisData): ServiceRedis)|(Closure(CreateServiceSolrData): ServiceSolr) expects CreateServiceRedisData, CreateServiceRedisData|CreateServiceSolrData given.
+77: Parameter #1 $data of callable (Closure(CreateServiceSolrData): ServiceSolr)|(Closure(CreateServiceRedisData): ServiceRedis) expects CreateServiceSolrData, CreateServiceRedisData|CreateServiceSolrData given.
Full report

PHP 8.0 – 8.1 (1 error)

Line Error
77 `Parameter #1 $data of callable (Closure(CreateServiceSolrData): ServiceSolr)

PHP 7.1 – 7.4 (3 errors)

Line Error
19 Promoted properties are supported only on PHP 8.0 and later.
31 Promoted properties are supported only on PHP 8.0 and later.
77 `Parameter #1 $data of callable (Closure(CreateServiceSolrData): ServiceSolr)

@phpstan-bot
Copy link
Contributor

@Kingdutch After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet:

@@ @@
 PHP 8.0 – 8.1 (1 error)
 ==========
 
-97: Parameter #1 $ of callable (callable(CreateServiceSolrData): ServiceSolr)|(callable(CreateServiceRedisData): ServiceRedis) expects CreateServiceSolrData, CreateServiceRedisData|CreateServiceSolrData given.
+97: Parameter #1 $ of callable (callable(CreateServiceRedisData): ServiceRedis)|(callable(CreateServiceSolrData): ServiceSolr) expects CreateServiceRedisData, CreateServiceRedisData|CreateServiceSolrData given.
 
 PHP 7.1 – 7.4 (3 errors)
 ==========
@@ @@
 
 19: Promoted properties are supported only on PHP 8.0 and later.
 31: Promoted properties are supported only on PHP 8.0 and later.
-97: Parameter #1 $ of callable (callable(CreateServiceSolrData): ServiceSolr)|(callable(CreateServiceRedisData): ServiceRedis) expects CreateServiceSolrData, CreateServiceRedisData|CreateServiceSolrData given.
+97: Parameter #1 $ of callable (callable(CreateServiceRedisData): ServiceRedis)|(callable(CreateServiceSolrData): ServiceSolr) expects CreateServiceRedisData, CreateServiceRedisData|CreateServiceSolrData given.
Full report

PHP 8.0 – 8.1 (1 error)

Line Error
97 `Parameter #1 $ of callable (callable(CreateServiceRedisData): ServiceRedis)

PHP 7.1 – 7.4 (3 errors)

Line Error
19 Promoted properties are supported only on PHP 8.0 and later.
31 Promoted properties are supported only on PHP 8.0 and later.
97 `Parameter #1 $ of callable (callable(CreateServiceRedisData): ServiceRedis)

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#2902

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 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants