mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Empty checks variables are really falsy checks
This commit is contained in:
parent
5ff3f1377d
commit
94e26b2257
@ -484,7 +484,16 @@ class AssertionFinder
|
||||
);
|
||||
|
||||
if ($var_name) {
|
||||
$if_types[$var_name] = [['empty']];
|
||||
if ($conditional->expr instanceof PhpParser\Node\Expr\Variable
|
||||
&& $source instanceof StatementsAnalyzer
|
||||
&& ($var_type = $source->node_data->getType($conditional->expr))
|
||||
&& !$var_type->isMixed()
|
||||
&& !$var_type->possibly_undefined
|
||||
) {
|
||||
$if_types[$var_name] = [['falsy']];
|
||||
} else {
|
||||
$if_types[$var_name] = [['empty']];
|
||||
}
|
||||
}
|
||||
|
||||
return $if_types;
|
||||
|
@ -1271,6 +1271,19 @@ class TypeAlgebraTest extends \Psalm\Tests\TestCase
|
||||
}',
|
||||
'error_message' => 'ParadoxicalCondition',
|
||||
],
|
||||
'mismatchingChecks' => [
|
||||
'<?php
|
||||
function doesntFindBug(?string $old, ?string $new): void {
|
||||
if (empty($old) && empty($new)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (($old && empty($new)) || ($new && empty($old))) {
|
||||
return;
|
||||
}
|
||||
}',
|
||||
'error_message' => 'RedundantCondition',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user