Skip to content

Dead catch rule vs union type catch #7312

@xificurk

Description

@xificurk

Feature request

Dead catch rule is currently evaluated using the whole combined type. If the catch block catches union of several exceptions, then as long as at least one of them is thrown, phpstan does not detect any error. It would be great if phpstan could detect those useless catches even inside union types.

Example: https://phpstan.org/r/544766d4-4ac3-4bce-946c-a4f0a340be55

In general, the catch type can get pretty complicated, but at least the most common use case - straight union of multiple types - could be unwrapped and analysed the same way as if written using individual catch blocks.

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

❤️

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions