Skip to content

Union of optional keyed arrays doesn't mean both keys exists at same time #7143

@rajyan

Description

@rajyan

Bug report

I'm investigating
#4809
#6508
#7000
and splitting them into smaller related issues.

If I union two optional keyed constant arrays array{foo?: string, bar: string}|array{foo: string, bar?: string} PHPStan generalize it as array{foo?: string, bar?: string}&non-empty-array (which I think is a correct and smart behavior) but this make it not report an error on offset access on both optional keys.

Code snippet that reproduces the problem

https://phpstan.org/r/519053c6-5183-449b-91ae-b27661281395

Expected output

Report for maybe not existing offset access in line 8,9,17,18

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

Yes! It' definitely a great tool already, and want to help making it even better!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions