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:
parent
f136fc3296
commit
6c9cdd896b
@ -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" />
|
||||
|
@ -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)
|
||||
|
6
src/Psalm/Issue/InvalidArrayOffset.php
Normal file
6
src/Psalm/Issue/InvalidArrayOffset.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace Psalm\Issue;
|
||||
|
||||
class InvalidArrayOffset extends CodeError
|
||||
{
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user