From fd4ced42a7332287d5750810665e2d2290ab2817 Mon Sep 17 00:00:00 2001 From: Brown Date: Fri, 31 Jul 2020 12:44:01 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20register=20new=20assignment=20i?= =?UTF-8?q?nside=20isset=20expr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Expression/AssignmentAnalyzer.php | 2 +- tests/ArrayAssignmentTest.php | 5 +---- tests/PropertyTypeTest.php | 18 ++++++++++++++++++ tests/TypeReconciliation/ValueTest.php | 8 +++++--- tests/UnusedCodeTest.php | 17 ----------------- tests/UnusedVariableTest.php | 17 +++++++++++++++++ 6 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index 1af668253..b96698d90 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -365,7 +365,7 @@ class AssignmentAnalyzer $location, $context->branch_point ); - } else { + } elseif (!$context->inside_isset) { $statements_analyzer->registerVariableAssignment( $var_id, $location diff --git a/tests/ArrayAssignmentTest.php b/tests/ArrayAssignmentTest.php index ac900ce1a..c7598da90 100644 --- a/tests/ArrayAssignmentTest.php +++ b/tests/ArrayAssignmentTest.php @@ -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; diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index 6abe66cd0..ad4349553 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -2023,6 +2023,24 @@ class PropertyTypeTest extends TestCase } }' ], + 'staticPropertyAssertion' => [ + ' [], - 'error_levels' => ['MixedOperand'], + 'error_levels' => ['MixedOperand', 'MixedAssignment'], ], 'incrementMixedCall' => [ ' [], - 'error_levels' => ['MissingParamType', 'MixedMethodCall', 'MixedOperand'], + 'error_levels' => ['MissingParamType', 'MixedMethodCall', 'MixedOperand', 'MixedAssignment'], ], 'regularValueReconciliation' => [ ' [ - ' $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' => [ ' [ + ' $keys + * @param int $key + */ + function error2(array $keys, int $key): int + { + if ($key === 1) {} + + do { + $nextKey = $keys[++$key] ?? null; + } while ($nextKey === null); + + return $nextKey; + }' + ], ]; }