Fix numeric-string negated intersection#1639
Conversation
e2ab2dc to
cb77b30
Compare
|
I've investigated a bit why that test with Actually, it's a hard problem. [
new Expr\BinaryOp\BooleanOr(
new Expr\BinaryOp\BooleanAnd(
$this->createFunctionCall('is_string', 'a'),
new NotIdentical(new String_(''), new Variable('a')),
),
new Identical(new Expr\ConstFetch(new Name('null')), new Variable('a')),
),
['$a' => 'non-empty-string|null'],
['$a' => 'mixed~non-empty-string & ~null'],
],becomes just |
|
I tested the my local test: <?php
function foo2(mixed $s): void
{
if (!is_numeric($s)) {
\PHPStan\dumpType($s);
}
}php bin/phpstan analyze test.php --debug
Note: Using configuration file /Users/staabm/workspace/phpstan-src/phpstan.neon.dist.
/Users/staabm/workspace/phpstan-src/test.php
------ ---------------------------------------------
Line test.php
------ ---------------------------------------------
6 Dumped type: mixed~float|int|numeric-string
------ ---------------------------------------------@fluffycondor please give me a ping in case you won't have time to finish it and I should push it over the finishing line |
089042f to
5376cd1
Compare
|
Thank you! |
Fixes phpstan/phpstan#7814
As the docs says:
https://phpstan.org/writing-php-code/phpdoc-types#other-advanced-string-types
So,
numeric-stringshould be also subtracted from any type not passedis_numeric, becauseis_numericis thenumeric-stringdeterminer itself.But I've added a test that shows there's a bug with
numeric-stringsubtraction frommixed. It's stillmixed. I would be glad if someone give me an advice how to fix it :)