Skip to content

Exception catch scope infers incorrect types #1670

@cs278

Description

@cs278

Summary of a problem or a feature request

Exception catch scope infers incorrect types. Apologies this isn't easy to describe and I didn't have any luck finding a similar issue. The code below is a minimum reproducer of the problem.

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

/** @var \stdClass|null */
$object = null;

try {
    if ($object === null) {
        throw new \InvalidArgumentException();
    }

    throw new \RuntimeException(); // If you remove this the same error is present as well, which makes even less sense to me
} catch (\Throwable $e) {
    if ($object === null) { // Strict comparison using === between stdClass and null will always evaluate to false.
    }
}

https://phpstan.org/r/c56d3540-d5fa-4366-8ca8-fb6bb63d2484

Expected output

No error

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions