1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Separate InvalidArrayAccess and InvalidArrayOffset

This commit is contained in:
Matthew Brown 2017-11-15 21:10:07 -05:00
parent f136fc3296
commit 6c9cdd896b
4 changed files with 12 additions and 4 deletions

View File

@ -102,6 +102,7 @@
<xs:element name="InvalidArgument" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InvalidArrayAccess" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InvalidArrayAssignment" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InvalidArrayOffset" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InvalidCast" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InvalidClass" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InvalidClone" type="IssueHandlerType" minOccurs="0" />

View File

@ -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)

View File

@ -0,0 +1,6 @@
<?php
namespace Psalm\Issue;
class InvalidArrayOffset extends CodeError
{
}

View File

@ -101,11 +101,11 @@ class ArrayAccessTest extends TestCase
echo $a[0];',
'error_message' => 'InvalidArrayAccess',
],
'invalidArrayAccess2' => [
'invalidArrayOffset' => [
'<?php
$x = ["a"];
$y = $x["b"];',
'error_message' => 'InvalidArrayAccess',
'error_message' => 'InvalidArrayOffset',
],
'possiblyInvalidArrayAccess' => [
'<?php