mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Don’t register new assignment inside isset expr
This commit is contained in:
parent
57cd21346c
commit
fd4ced42a7
@ -365,7 +365,7 @@ class AssignmentAnalyzer
|
||||
$location,
|
||||
$context->branch_point
|
||||
);
|
||||
} else {
|
||||
} elseif (!$context->inside_isset) {
|
||||
$statements_analyzer->registerVariableAssignment(
|
||||
$var_id,
|
||||
$location
|
||||
|
@ -997,10 +997,7 @@ class ArrayAssignmentTest extends TestCase
|
||||
$a = [];
|
||||
|
||||
foreach (["one", "two", "three"] as $key) {
|
||||
/**
|
||||
* @psalm-suppress MixedOperand
|
||||
*/
|
||||
$a[$key] += rand(0, 10);
|
||||
$a[$key] += rand(0, 10);
|
||||
}
|
||||
|
||||
$a["four"] = true;
|
||||
|
@ -2023,6 +2023,24 @@ class PropertyTypeTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'staticPropertyAssertion' => [
|
||||
'<?php
|
||||
class Foo {
|
||||
/** @var int */
|
||||
private static $transactionDepth;
|
||||
|
||||
function bar(): void {
|
||||
if (self::$transactionDepth === 0) {
|
||||
} else {
|
||||
--self::$transactionDepth;
|
||||
|
||||
if (self::$transactionDepth === 0) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -233,12 +233,14 @@ class ValueTest extends TestCase
|
||||
'<?php
|
||||
$i = 0;
|
||||
$a = function() use (&$i) : void {
|
||||
if (rand(0, 1)) $i++;
|
||||
if (rand(0, 1)) {
|
||||
$i++;
|
||||
}
|
||||
};
|
||||
$a();
|
||||
if ($i === 0) {}',
|
||||
'assertions' => [],
|
||||
'error_levels' => ['MixedOperand'],
|
||||
'error_levels' => ['MixedOperand', 'MixedAssignment'],
|
||||
],
|
||||
'incrementMixedCall' => [
|
||||
'<?php
|
||||
@ -250,7 +252,7 @@ class ValueTest extends TestCase
|
||||
if ($i === 0) {}
|
||||
}',
|
||||
'assertions' => [],
|
||||
'error_levels' => ['MissingParamType', 'MixedMethodCall', 'MixedOperand'],
|
||||
'error_levels' => ['MissingParamType', 'MixedMethodCall', 'MixedOperand', 'MixedAssignment'],
|
||||
],
|
||||
'regularValueReconciliation' => [
|
||||
'<?php
|
||||
|
@ -719,23 +719,6 @@ 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;
|
||||
}'
|
||||
],
|
||||
'arrayPushFunctionCall' => [
|
||||
'<?php
|
||||
$a = [];
|
||||
|
@ -1461,6 +1461,23 @@ class UnusedVariableTest extends TestCase
|
||||
return $i + 1;
|
||||
}'
|
||||
],
|
||||
'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