mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix a couple of false-positive redundant conditions
This commit is contained in:
parent
1b10f11217
commit
ec64ae930a
@ -2151,6 +2151,14 @@ class AssertionFinder
|
||||
$literal_assertions[] = '=' . $array_literal_type->getId();
|
||||
}
|
||||
|
||||
if ($atomic_type->type_params[1]->isFalsable()) {
|
||||
$literal_assertions[] = 'false';
|
||||
}
|
||||
|
||||
if ($atomic_type->type_params[1]->isNullable()) {
|
||||
$literal_assertions[] = 'null';
|
||||
}
|
||||
|
||||
if ($negate) {
|
||||
$if_types = \Psalm\Type\Algebra::negateTypes([
|
||||
$first_var_name => [$literal_assertions]
|
||||
|
@ -945,6 +945,8 @@ class TypeCombination
|
||||
}
|
||||
}
|
||||
|
||||
$has_defined_keys = false;
|
||||
|
||||
foreach ($type->properties as $candidate_property_name => $candidate_property_type) {
|
||||
$value_type = isset($combination->objectlike_entries[$candidate_property_name])
|
||||
? $combination->objectlike_entries[$candidate_property_name]
|
||||
@ -973,6 +975,14 @@ class TypeCombination
|
||||
if (!$type->previous_value_type) {
|
||||
unset($possibly_undefined_entries[$candidate_property_name]);
|
||||
}
|
||||
|
||||
if (!$candidate_property_type->possibly_undefined) {
|
||||
$has_defined_keys = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$has_defined_keys) {
|
||||
$combination->array_always_filled = false;
|
||||
}
|
||||
|
||||
if ($combination->array_counts !== null) {
|
||||
|
@ -629,6 +629,13 @@ class TypeCombinationTest extends TestCase
|
||||
'positive-int',
|
||||
],
|
||||
],
|
||||
'combinNonEmptyArrayAndKeyedArray' => [
|
||||
'array<int, int>',
|
||||
[
|
||||
'non-empty-array<int, int>',
|
||||
'array{0?:int}',
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -766,6 +766,16 @@ class ValueTest extends \Psalm\Tests\TestCase
|
||||
return $ret;
|
||||
}'
|
||||
],
|
||||
'inArrayPreserveNull' => [
|
||||
'<?php
|
||||
function x(?string $foo): void {
|
||||
if (!in_array($foo, ["foo", "bar", null], true)) {
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
if ($foo) {}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user