From 9061d36566bcf4d7f26dbfcebf263c93b7630382 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 12 Feb 2017 17:13:03 -0500 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20emit=20InvalidArrayAccess=20if?= =?UTF-8?q?=20ignoring=20null=20arrays?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Statements/Expression/FetchChecker.php | 15 +++++++++------ tests/ArrayAccessTest.php | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Psalm/Checker/Statements/Expression/FetchChecker.php b/src/Psalm/Checker/Statements/Expression/FetchChecker.php index 68909b937..7876295bc 100644 --- a/src/Psalm/Checker/Statements/Expression/FetchChecker.php +++ b/src/Psalm/Checker/Statements/Expression/FetchChecker.php @@ -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) { diff --git a/tests/ArrayAccessTest.php b/tests/ArrayAccessTest.php index 02d2f47ce..16127c033 100644 --- a/tests/ArrayAccessTest.php +++ b/tests/ArrayAccessTest.php @@ -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('project_checker, $stmts); + $file_checker->visitAndAnalyzeMethods($context); + } }