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:
parent
052d4f6217
commit
c7016d9232
@ -549,6 +549,8 @@ class SwitchChecker
|
||||
$type
|
||||
);
|
||||
}
|
||||
} else {
|
||||
unset($new_vars_in_scope[$var_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user