Feature request
In the following case, if I narrow the computed value $class, then the original value $x is narrowed accordingly:
function test_if(mixed $x) {
if ($x === 'aa')
$class = 'some_class';
elseif ($x === 'bb' || $x === 'cc')
$class = 'another_class';
else
$class = null;
if ($class === null)
return;
\PHPStan\dumpType($x); // 'aa'|'bb'|'cc'
};
I want the same when I use match() instead of if:
function test_match(mixed $x) {
$class = match ($x) {
'aa' => 'some_class',
'bb', 'cc' => 'another_class',
default => null,
};
if ($class === null)
return;
\PHPStan\dumpType($x); // expected: 'aa'|'bb'|'cc'; actual: mixed
};
Code snippet
https://phpstan.org/r/6a443593-a414-49ff-ab67-ea675e7b3452
Did PHPStan help you today? Did it make you happy in any way?
No response
Feature request
In the following case, if I narrow the computed value
$class, then the original value$xis narrowed accordingly:I want the same when I use
match()instead ofif:Code snippet
https://phpstan.org/r/6a443593-a414-49ff-ab67-ea675e7b3452
Did PHPStan help you today? Did it make you happy in any way?
No response