Bug report
When a generic type is compared with a value, the type information is lost.
<?php
enum Foo {
case Abc;
case Bcd;
}
/**
* @template TFoo of Foo::*
* @param TFoo $foo
*/
function checkFoo($foo): void {
}
/**
* @template TFoo of Foo::*
* @param TFoo $foo
*/
function getFoo1($foo): void {
$filter = Foo::Abc === $foo ? 'Abc' : 'Bcd';
checkFoo($foo); // Error: Parameter #1 $foo of function checkFoo expects Foo::Abc|Foo::Bcd, TFoo given.
}
/**
* @template TFoo of Foo::*
* @param TFoo $foo
*/
function getFoo2($foo): void {
checkFoo($foo);
}
Code snippet that reproduces the problem
https://phpstan.org/r/7118dd81-84cc-40cb-826f-8ae2c8caa2f3
Expected output
PHPStan should not forget the type of the generic variable.
Did PHPStan help you today? Did it make you happy in any way?
No response
Bug report
When a generic type is compared with a value, the type information is lost.
Code snippet that reproduces the problem
https://phpstan.org/r/7118dd81-84cc-40cb-826f-8ae2c8caa2f3
Expected output
PHPStan should not forget the type of the generic variable.
Did PHPStan help you today? Did it make you happy in any way?
No response