1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix erroneous empty array creation in SwitchChecker

Fixes #354
This commit is contained in:
Matthew Brown 2017-11-28 22:33:37 -05:00
parent 6c9d90850a
commit f4212d897c
2 changed files with 22 additions and 2 deletions

View File

@ -180,8 +180,6 @@ class SwitchChecker
if ($possibly_redefined_vars === null) {
$possibly_redefined_vars = $case_redefined_vars;
} else {
$possibly_redefined_vars = [];
foreach ($case_redefined_vars as $var_id => $type) {
if (!isset($possibly_redefined_vars[$var_id])) {
$possibly_redefined_vars[$var_id] = $type;

View File

@ -201,6 +201,28 @@ class SwitchTypeTest extends TestCase
throw new RuntimeException("none found");
}',
],
'switchBools' => [
'<?php
$x = false;
$y = false;
foreach ([1, 2, 3] as $v) {
switch($v) {
case 3:
$y = true;
break;
case 2:
$x = true;
break;
default:
break;
}
}',
'assertions' => [
'$x' => 'bool',
'$y' => 'bool',
],
],
];
}