From 6c9cdd896bac759dcc335877624a3d6ff7e87eac Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Wed, 15 Nov 2017 21:10:07 -0500 Subject: [PATCH] Separate InvalidArrayAccess and InvalidArrayOffset --- config.xsd | 1 + src/Psalm/Checker/Statements/Expression/FetchChecker.php | 5 +++-- src/Psalm/Issue/InvalidArrayOffset.php | 6 ++++++ tests/ArrayAccessTest.php | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 src/Psalm/Issue/InvalidArrayOffset.php diff --git a/config.xsd b/config.xsd index 9928e7153..b78bce47e 100644 --- a/config.xsd +++ b/config.xsd @@ -102,6 +102,7 @@ + diff --git a/src/Psalm/Checker/Statements/Expression/FetchChecker.php b/src/Psalm/Checker/Statements/Expression/FetchChecker.php index e554b3548..5e9f08818 100644 --- a/src/Psalm/Checker/Statements/Expression/FetchChecker.php +++ b/src/Psalm/Checker/Statements/Expression/FetchChecker.php @@ -16,6 +16,7 @@ use Psalm\Issue\EmptyArrayAccess; use Psalm\Issue\InaccessibleClassConstant; use Psalm\Issue\InvalidArrayAccess; use Psalm\Issue\InvalidArrayAssignment; +use Psalm\Issue\InvalidArrayOffset; use Psalm\Issue\InvalidPropertyFetch; use Psalm\Issue\MissingPropertyType; use Psalm\Issue\MixedArrayAccess; @@ -1146,7 +1147,7 @@ class FetchChecker $stmt->inferredType = clone $type->properties[(string)$int_key_value]; } elseif ($used_key_type->hasInt()) { if (IssueBuffer::accepts( - new InvalidArrayAccess( + new InvalidArrayOffset( 'Cannot access value on array variable ' . $var_id . ' using int offset - ' . 'expecting ' . $expected_keys_string, new CodeLocation($statements_checker->getSource(), $stmt) @@ -1254,7 +1255,7 @@ class FetchChecker } } elseif (!$at->isIn($project_checker, $inferred_key_type)) { if (IssueBuffer::accepts( - new InvalidArrayAccess( + new InvalidArrayOffset( 'Cannot access value on variable ' . $var_id . ' using ' . $at . ' offset - ' . 'expecting ' . $inferred_key_type, new CodeLocation($statements_checker->getSource(), $stmt) diff --git a/src/Psalm/Issue/InvalidArrayOffset.php b/src/Psalm/Issue/InvalidArrayOffset.php new file mode 100644 index 000000000..fded4d5e7 --- /dev/null +++ b/src/Psalm/Issue/InvalidArrayOffset.php @@ -0,0 +1,6 @@ + 'InvalidArrayAccess', ], - 'invalidArrayAccess2' => [ + 'invalidArrayOffset' => [ ' 'InvalidArrayAccess', + 'error_message' => 'InvalidArrayOffset', ], 'possiblyInvalidArrayAccess' => [ '