1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fixed coercion of mixed into non-empty-mixed

Fixes vimeo/psalm#9540
This commit is contained in:
Bruce Weirdan 2023-03-19 00:49:15 -04:00
parent c2c2e26d6d
commit b25f2e6921
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
3 changed files with 11 additions and 6 deletions

View File

@ -26,6 +26,7 @@ use Psalm\Type\Atomic\TMixed;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TNever;
use Psalm\Type\Atomic\TNonEmptyArray;
use Psalm\Type\Atomic\TNonEmptyMixed;
use Psalm\Type\Atomic\TNull;
use Psalm\Type\Atomic\TObject;
use Psalm\Type\Atomic\TObjectWithProperties;
@ -87,8 +88,11 @@ class AtomicTypeComparator
&& !$container_type_part->extra_types
&& $input_type_part instanceof TMixed)
) {
if (get_class($container_type_part) === TEmptyMixed::class
&& get_class($input_type_part) === TMixed::class
if (get_class($input_type_part) === TMixed::class
&& (
get_class($container_type_part) === TEmptyMixed::class
|| get_class($container_type_part) === TNonEmptyMixed::class
)
) {
if ($atomic_comparison_result) {
$atomic_comparison_result->type_coerced = true;

View File

@ -44,7 +44,7 @@ class UnionTypeComparator
bool $allow_interface_equality = false,
bool $allow_float_int_equality = true
): bool {
if ($container_type->isMixed()) {
if ($container_type->isVanillaMixed()) {
return true;
}
@ -63,9 +63,6 @@ class UnionTypeComparator
return false;
}
if ($container_type->hasMixed() && !$container_type->isEmptyMixed()) {
return true;
}
$container_has_template = $container_type->hasTemplateOrStatic();

View File

@ -173,5 +173,9 @@ class TypeComparatorTest extends TestCase
'list<int>',
'array{int, string}',
];
yield 'nonEmptyMixedDoesNotAcceptMixed' => [
'non-empty-mixed',
'mixed',
];
}
}