1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +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 committed by Daniil Gentili
parent 0b5a828f6f
commit bd8df0e820
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
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]; $new_type = $new_vars_in_scope[$var_id];
if (!$this_type->isEmpty() if (!$this_type->equals($new_type)) {
&& !$new_type->isEmpty()
&& !$this_type->equals($new_type)
) {
$redefined_vars[$var_id] = $this_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;
}'
],
]; ];
} }