Skip to content

Switch branch with fall-through not narrowing values properly #11064

@uuf6429

Description

@uuf6429

Bug report

After some trial and error, it seems that the first branch (the one we are falling though) does not narrow the value type for follow up branches.

For example, if you swap lines 12-13 in the provided example, the warning changes to get_class expects object, IClass|string given (instead of IClass|null). Unless I'm missing something, this would be a bug, since other branches seem to work fine.

Note: for my current use-case, and in general, splitting the branches (without fall-throughs) is a good workaround.

Code snippet that reproduces the problem

https://phpstan.org/r/46475e6a-20c2-476c-860d-ff70a934b449

Expected output

There shouldn't be any warnings, since both types/branches are actually handled.

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions