1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Don’t emit InvalidArrayAccess if ignoring null arrays

This commit is contained in:
Matthew Brown 2017-02-12 17:13:03 -05:00
parent 2635744f4e
commit 9061d36566
2 changed files with 26 additions and 6 deletions

View File

@ -869,13 +869,16 @@ class FetchChecker
),
$statements_checker->getSuppressedIssues()
)) {
if (isset($stmt->inferredType)) {
$stmt->inferredType = Type::combineUnionTypes($stmt->inferredType, Type::getNull());
} else {
$stmt->inferredType = Type::getNull();
}
continue;
// fall through
}
if (isset($stmt->inferredType)) {
$stmt->inferredType = Type::combineUnionTypes($stmt->inferredType, Type::getNull());
} else {
$stmt->inferredType = Type::getNull();
}
continue;
}
if ($type instanceof Type\Atomic\TArray || $type instanceof Type\Atomic\ObjectLike) {

View File

@ -210,4 +210,21 @@ class ArrayAccessTest extends PHPUnit_Framework_TestCase
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$file_checker->visitAndAnalyzeMethods($context);
}
/**
* @return void
*/
public function testIgnorePossiblyNullArrayAccess()
{
Config::getInstance()->setCustomErrorLevel('PossiblyNullArrayAccess', Config::REPORT_SUPPRESS);
$context = new Context();
$stmts = self::$parser->parse('<?php
$a = rand(0, 1) ? [1, 2] : null;
echo $a[0];
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$file_checker->visitAndAnalyzeMethods($context);
}
}