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

Fix #3802 - allow increment inside isset expression

This commit is contained in:
Brown 2020-07-10 16:14:24 -04:00
parent 4f872674f9
commit d71f12d250
2 changed files with 26 additions and 5 deletions

View File

@ -88,11 +88,15 @@ class IncDecExpressionAnalyzer
$location = new CodeLocation($statements_analyzer, $stmt->var);
$context->assigned_var_ids[$var_id] = true;
$context->possibly_assigned_var_ids[$var_id] = true;
$statements_analyzer->registerVariableAssignment(
$var_id,
$location
);
$context->unreferenced_vars[$var_id] = [$location->getHash() => $location];
if (!$context->inside_isset || !$context->inside_loop) {
$statements_analyzer->registerVariableAssignment(
$var_id,
$location
);
$context->unreferenced_vars[$var_id] = [$location->getHash() => $location];
}
}
// removes dependent vars from $context

View File

@ -719,6 +719,23 @@ class UnusedCodeTest extends TestCase
$methodRef = "\A::b";
$methodRef();',
],
'doArrayIncrement' => [
'<?php
/**
* @param list<int> $keys
* @param int $key
*/
function error2(array $keys, int $key): int
{
if ($key === 1) {}
do {
$nextKey = $keys[++$key] ?? null;
} while ($nextKey === null);
return $nextKey;
}'
],
];
}