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

Fix issue with do analysis while loops

This commit is contained in:
Matthew Brown 2019-01-07 01:15:30 -05:00
parent 36a1fe07da
commit bcbede07ba
2 changed files with 16 additions and 24 deletions

View File

@ -135,29 +135,7 @@ class DoAnalyzer
$do_context->vars_in_scope = $while_vars_in_scope_reconciled; $do_context->vars_in_scope = $while_vars_in_scope_reconciled;
} }
$do_cond_context = clone $do_context; foreach ($do_context->vars_in_scope as $var_id => $type) {
if (!in_array('RedundantCondition', $suppressed_issues, true)) {
$statements_analyzer->addSuppressedIssues(['RedundantCondition']);
}
if (!in_array('RedundantConditionGivenDocblockType', $suppressed_issues, true)) {
$statements_analyzer->addSuppressedIssues(['RedundantConditionGivenDocblockType']);
}
ExpressionAnalyzer::analyze($statements_analyzer, $stmt->cond, $do_cond_context);
if (!in_array('RedundantCondition', $suppressed_issues, true)) {
$statements_analyzer->removeSuppressedIssues(['RedundantCondition']);
}
if (!in_array('RedundantConditionGivenDocblockType', $suppressed_issues, true)) {
$statements_analyzer->removeSuppressedIssues(['RedundantConditionGivenDocblockType']);
}
if ($context->collect_references) {
$do_context->unreferenced_vars = $do_cond_context->unreferenced_vars;
}
foreach ($do_cond_context->vars_in_scope as $var_id => $type) {
if (isset($context->vars_in_scope[$var_id])) { if (isset($context->vars_in_scope[$var_id])) {
$context->vars_in_scope[$var_id] = Type::combineUnionTypes($context->vars_in_scope[$var_id], $type); $context->vars_in_scope[$var_id] = Type::combineUnionTypes($context->vars_in_scope[$var_id], $type);
} }
@ -232,7 +210,7 @@ class DoAnalyzer
); );
if ($context->collect_references) { if ($context->collect_references) {
$context->unreferenced_vars = $do_context->unreferenced_vars; $context->unreferenced_vars = $inner_loop_context->unreferenced_vars;
} }
if ($context->collect_exceptions) { if ($context->collect_exceptions) {

View File

@ -256,6 +256,20 @@ class DoTest extends \Psalm\Tests\TestCase
$a = $a->getParent(); $a = $a->getParent();
} while ($a !== false);', } while ($a !== false);',
], ],
'doCallInWhile' => [
'<?php
class A {
public function getParent() : ?A {
return rand(0, 1) ? new A : null;
}
}
$a = new A();
$i = 0;
do {
$i++;
} while ($a = $a->getParent());'
],
'doWithContinue' => [ 'doWithContinue' => [
'<?php '<?php
do { do {