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:
parent
4f872674f9
commit
d71f12d250
@ -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
|
||||
|
@ -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;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user