mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #1598, catching unused variables followed by try inside loop
This commit is contained in:
parent
86bf159bd0
commit
08bf101f48
@ -342,7 +342,7 @@ class TryAnalyzer
|
||||
|
||||
if ($catch_actions[$i] !== [ScopeAnalyzer::ACTION_END]) {
|
||||
foreach ($catch_context->vars_in_scope as $var_id => $type) {
|
||||
if ($context->hasVariable($var_id)
|
||||
if (isset($context->vars_in_scope[$var_id])
|
||||
&& $context->vars_in_scope[$var_id]->getId() !== $type->getId()
|
||||
) {
|
||||
$context->vars_in_scope[$var_id] = Type::combineUnionTypes(
|
||||
|
@ -294,7 +294,7 @@ class UnusedCodeTest extends TestCase
|
||||
public function bar() : void {
|
||||
$c = $this->getC();
|
||||
|
||||
foreach ([1, 2, 3] as $i) {
|
||||
foreach ([1, 2, 3] as $_) {
|
||||
try {
|
||||
$c->foo();
|
||||
} catch (Exception $e) {}
|
||||
|
@ -1427,6 +1427,17 @@ class UnusedVariableTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'UnusedVariable',
|
||||
],
|
||||
'detectUnusedVarBeforeTryInsideForeach' => [
|
||||
'<?php
|
||||
function foo() : void {
|
||||
$unused = 1;
|
||||
|
||||
while (rand(0, 1)) {
|
||||
try {} catch (\Exception $e) {}
|
||||
}
|
||||
}',
|
||||
'error_message' => 'UnusedVariable',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user