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

Allow dead code detection to capture last do checks

This commit is contained in:
Matthew Brown 2018-06-30 11:08:51 -04:00
parent 6267fa7d1d
commit 5ed062257b
2 changed files with 12 additions and 4 deletions

View File

@ -158,14 +158,14 @@ class DoChecker
$do_context->referenced_var_ids
);
ExpressionChecker::analyze($statements_checker, $stmt->cond, $inner_loop_context);
if ($context->collect_references) {
$context->unreferenced_vars = $do_context->unreferenced_vars;
$context->unreferenced_vars = $inner_loop_context->unreferenced_vars;
}
if ($context->collect_exceptions) {
$context->possibly_thrown_exceptions += $do_context->possibly_thrown_exceptions;
$context->possibly_thrown_exceptions += $inner_loop_context->possibly_thrown_exceptions;
}
ExpressionChecker::analyze($statements_checker, $stmt->cond, $inner_loop_context);
}
}

View File

@ -847,6 +847,14 @@ class UnusedVariableTest extends TestCase
exit;
}',
],
'usedVariableInDoWhile' => [
'<?php
$i = 5;
do {
echo "hello";
} while (--$i > 0);
echo $i;',
],
];
}