Skip to content

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

@Kingdutch

Description

@Kingdutch

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions