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:
parent
2635744f4e
commit
9061d36566
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user