mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix issue with do analysis while loops
This commit is contained in:
parent
36a1fe07da
commit
bcbede07ba
@ -135,29 +135,7 @@ class DoAnalyzer
|
||||
$do_context->vars_in_scope = $while_vars_in_scope_reconciled;
|
||||
}
|
||||
|
||||
$do_cond_context = clone $do_context;
|
||||
|
||||
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) {
|
||||
foreach ($do_context->vars_in_scope as $var_id => $type) {
|
||||
if (isset($context->vars_in_scope[$var_id])) {
|
||||
$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) {
|
||||
$context->unreferenced_vars = $do_context->unreferenced_vars;
|
||||
$context->unreferenced_vars = $inner_loop_context->unreferenced_vars;
|
||||
}
|
||||
|
||||
if ($context->collect_exceptions) {
|
||||
|
@ -256,6 +256,20 @@ class DoTest extends \Psalm\Tests\TestCase
|
||||
$a = $a->getParent();
|
||||
} 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' => [
|
||||
'<?php
|
||||
do {
|
||||
|
Loading…
Reference in New Issue
Block a user