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:
parent
a53cc23809
commit
d10a06837d
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user