mirror of
https://github.com/danog/psalm.git
synced 2024-12-03 10:07:52 +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);
|
$location = new CodeLocation($statements_analyzer, $stmt->var);
|
||||||
$context->assigned_var_ids[$var_id] = true;
|
$context->assigned_var_ids[$var_id] = true;
|
||||||
$context->possibly_assigned_var_ids[$var_id] = true;
|
$context->possibly_assigned_var_ids[$var_id] = true;
|
||||||
$statements_analyzer->registerVariableAssignment(
|
|
||||||
$var_id,
|
if (!$context->inside_isset || !$context->inside_loop) {
|
||||||
$location
|
$statements_analyzer->registerVariableAssignment(
|
||||||
);
|
$var_id,
|
||||||
$context->unreferenced_vars[$var_id] = [$location->getHash() => $location];
|
$location
|
||||||
|
);
|
||||||
|
|
||||||
|
$context->unreferenced_vars[$var_id] = [$location->getHash() => $location];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes dependent vars from $context
|
// removes dependent vars from $context
|
||||||
|
@ -719,6 +719,23 @@ class UnusedCodeTest extends TestCase
|
|||||||
$methodRef = "\A::b";
|
$methodRef = "\A::b";
|
||||||
$methodRef();',
|
$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