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

Add better handling of catch-reassigned vars

Ref #2052
This commit is contained in:
Brown 2019-08-26 11:41:15 -04:00
parent f4f4a32f08
commit febd60dade
2 changed files with 16 additions and 0 deletions

View File

@ -362,6 +362,8 @@ class TryAnalyzer
&& $old_unreferenced_vars[$var_id] !== $locations
) {
$statements_analyzer->registerVariableUses($locations);
} elseif (isset($newly_unreferenced_vars[$var_id])) {
$context->unreferenced_vars[$var_id] = $newly_unreferenced_vars[$var_id];
}
}
}

View File

@ -1088,6 +1088,20 @@ class UnusedVariableTest extends TestCase
$a->bar($i);
}',
],
'noUnusedVariableAfterRedeclaredInCatch' => [
'<?php
$path = "";
echo $path;
try {
// do nothing
} catch (\Exception $exception) {
$path = "hello";
}
echo $path;'
],
];
}