1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #5784 - only real-asserted variables from context knowledge

Any assertions added in the addNestedAssertions method should not illegitimise current knowledge
This commit is contained in:
Matt Brown 2021-05-17 15:11:27 -05:00
parent 836587ec1d
commit 787c0f30d6
2 changed files with 27 additions and 1 deletions

View File

@ -96,7 +96,8 @@ class Reconciler
$has_falsyish = false;
$has_empty = false;
$has_count_check = false;
$is_equality = ($old_new_types[$key] ?? null) === $new_type_parts;
$is_real = ($old_new_types[$key] ?? null) === $new_type_parts;
$is_equality = $is_real;
foreach ($new_type_parts as $new_type_part_parts) {
foreach ($new_type_part_parts as $new_type_part_part) {
@ -271,6 +272,7 @@ class Reconciler
if (!isset($new_types[$new_key])
&& preg_match('/' . preg_quote($key, '/') . '[\]\[\-]/', $new_key)
&& $is_real
) {
unset($existing_types[$new_key]);
}

View File

@ -389,6 +389,30 @@ class EmptyTest extends \Psalm\Tests\TestCase
echo $arr["a"];
}'
],
'reconcileEmptyTwiceWithoutReturn' => [
'<?php
function foo(array $arr): void {
if (!empty($arr["a"])) {
} else {
if (empty($arr["dontcare"])) {}
}
if (empty($arr["a"])) {}
}'
],
'reconcileEmptyTwiceWithReturn' => [
'<?php
function foo(array $arr): void {
if (!empty($arr["a"])) {
} else {
if (empty($arr["dontcare"])) {
return;
}
}
if (empty($arr["a"])) {}
}'
],
];
}