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

Merge pull request #10134 from weirdan/fix-10132

This commit is contained in:
Bruce Weirdan 2023-08-20 23:54:31 +02:00 committed by GitHub
commit e085b73f2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -1737,8 +1737,10 @@ class ArrayFetchAnalyzer
?Union &$array_access_type,
bool &$has_array_access
): void {
$codebase = $statements_analyzer->getCodebase();
if (strtolower($type->value) === 'simplexmlelement'
|| $statements_analyzer->getCodebase()->classExtendsOrImplements($type->value, 'SimpleXMLElement')
|| ($codebase->classExists($type->value)
&& $codebase->classExtendsOrImplements($type->value, 'SimpleXMLElement'))
) {
$call_array_access_type = new Union([new TNull(), new TNamedObject('SimpleXMLElement')]);
} elseif (strtolower($type->value) === 'domnodelist' && $stmt->dim) {

View File

@ -1199,6 +1199,27 @@ class ArrayAccessTest extends TestCase
',
'assertions' => ['$a===' => "array{1: 'b'}"],
],
'noCrashOnUnknownClassArrayAccess' => [
'code' => <<<'PHP'
<?php
namespace Psalmtest\Psalmtest;
use SomeMissingClass;
class Test
{
public function f(): void {
/** @var SomeMissingClass */
$result = null;
if ($result['errors'] === true) {}
}
}
PHP,
'assertions' => [],
'ignored_issues' => ['UndefinedDocblockClass'],
],
];
}