1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix #5001 - update variables after context after type change from empty

Empty is the invalid state, and some old logic here was causing a bug
This commit is contained in:
Matt Brown 2021-01-13 11:35:44 -05:00
parent a53cc23809
commit d10a06837d
2 changed files with 39 additions and 4 deletions

View File

@ -463,10 +463,7 @@ class Context
$new_type = $new_vars_in_scope[$var_id];
if (!$this_type->isEmpty()
&& !$new_type->isEmpty()
&& !$this_type->equals($new_type)
) {
if (!$this_type->equals($new_type)) {
$redefined_vars[$var_id] = $this_type;
}
}

View File

@ -585,6 +585,44 @@ class WhileTest extends \Psalm\Tests\TestCase
}
}'
],
'ifNestedInsideLoop' => [
'<?php
function analyse(): int {
$state = 1;
while (rand(0, 1)) {
if ($state === 3) {
echo "here";
} elseif ($state === 2) {
if (rand(0, 1)) {
$state = 3;
}
} else {
$state = 2;
}
}
return $state;
}'
],
'ifNotNestedInsideLoop' => [
'<?php
function analyse(): int {
$state = 1;
while (rand(0, 1)) {
if ($state === 3) {
echo "here";
} elseif ($state === 2) {
$state = 3;
} else {
$state = 2;
}
}
return $state;
}'
],
];
}