Bug report
If in a try block I set a variable to an instance of a generic class where the generic type is mixed, and in the corresponding catch block I set that variable to an instance of the same generic class but with a specific generic type (e.g. int,) then afterwards PHPStan incorrectly sees that variable as always having the more specific generic type.
try {
/** @var mixed */
$bar = 'bar';
$foo = new Foo($bar);
} catch (\Exception $e) {
$foo = new Foo(123);
}
PHPStan\dumpType($foo); // returns Foo<int>
Code snippet that reproduces the problem
https://phpstan.org/r/2d6bc77c-c571-4e65-b4eb-53b69b8f59d9
Expected output
No issue should be detected.
PHPStan should see the type of $foo as Foo<mixed>|Foo<int> (or possibly Foo<mixed>.)
Did PHPStan help you today? Did it make you happy in any way?
PHPStan makes me happy by finding bugs before they wake me up for a 3am production bug.
Bug report
If in a
tryblock I set a variable to an instance of a generic class where the generic type ismixed, and in the correspondingcatchblock I set that variable to an instance of the same generic class but with a specific generic type (e.g.int,) then afterwards PHPStan incorrectly sees that variable as always having the more specific generic type.Code snippet that reproduces the problem
https://phpstan.org/r/2d6bc77c-c571-4e65-b4eb-53b69b8f59d9
Expected output
No issue should be detected.
PHPStan should see the type of
$fooasFoo<mixed>|Foo<int>(or possiblyFoo<mixed>.)Did PHPStan help you today? Did it make you happy in any way?
PHPStan makes me happy by finding bugs before they wake me up for a 3am production bug.