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

SimpleXMLIterator is not always truthy

Fixes #6865
This commit is contained in:
Jonathan Vollebregt 2021-11-12 13:49:00 +01:00
parent 2d0758ab10
commit f5d7f6c405
3 changed files with 15 additions and 1 deletions

View File

@ -1088,7 +1088,8 @@ class Union implements TypeNode
}
if ($atomic_type instanceof Type\Atomic\TNamedObject
&& $atomic_type->value !== 'SimpleXMLElement') {
&& $atomic_type->value !== 'SimpleXMLElement'
&& $atomic_type->value !== 'SimpleXMLIterator') {
continue;
}

View File

@ -2821,6 +2821,17 @@ class ConditionalTest extends \Psalm\Tests\TestCase
function b(B $_b): void {
}',
],
'SimpleXMLIteratorNotAlwaysTruthy' => [
'<?php
$lilstring = "";
$n = new SimpleXMLElement($lilstring);
$n = $n->children();
if (!$n) {
echo "false";
}',
],
];
}

View File

@ -146,6 +146,8 @@ class ReconcilerTest extends \Psalm\Tests\TestCase
'filterKeyedArrayWithIterable' => ['array{some: string}', 'iterable<string>', 'array{some: mixed}'],
'SimpleXMLElementNotAlwaysTruthy' => ['SimpleXMLElement', '!falsy', 'SimpleXMLElement'],
'SimpleXMLElementNotAlwaysTruthy2' => ['SimpleXMLElement', 'falsy', 'SimpleXMLElement'],
'SimpleXMLIteratorNotAlwaysTruthy' => ['SimpleXMLIterator', '!falsy', 'SimpleXMLIterator'],
'SimpleXMLIteratorNotAlwaysTruthy2' => ['SimpleXMLIterator', 'falsy', 'SimpleXMLIterator'],
];
}