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

Unset new var if it doesn’t appear in break vars

This commit is contained in:
Matthew Brown 2018-11-11 22:03:08 -05:00
parent 052d4f6217
commit c7016d9232
2 changed files with 20 additions and 0 deletions

View File

@ -549,6 +549,8 @@ class SwitchChecker
$type
);
}
} else {
unset($new_vars_in_scope[$var_id]);
}
}
}

View File

@ -484,6 +484,7 @@ class SwitchTypeTest extends TestCase
'<?php
switch (rand(0, 4)) {
case 0:
$b = 2;
if (rand(0, 1)) {
$a = false;
break;
@ -741,6 +742,23 @@ class SwitchTypeTest extends TestCase
}',
'error_message' => 'ParadoxicalCondition - src/somefile.php:11',
],
'breakWithoutSettingVar' => [
'<?php
function foo(int $i) : void {
switch ($i) {
case 0:
if (rand(0, 1)) {
break;
}
default:
$a = true;
}
if ($a) {}
}',
'error_message' => 'PossiblyUndefinedVariable'
],
];
}
}