Skip to content

Commit

Permalink
Merge pull request #9541 from weirdan/mixed-types-coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Mar 19, 2023
2 parents c2c2e26 + b25f2e6 commit b381f47
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -87,8 +88,11 @@ public static function isContainedBy(
&& !$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;
Expand Down
5 changes: 1 addition & 4 deletions src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function isContainedBy(
bool $allow_interface_equality = false,
bool $allow_float_int_equality = true
): bool {
if ($container_type->isMixed()) {
if ($container_type->isVanillaMixed()) {
return true;
}

Expand All @@ -63,9 +63,6 @@ public static function isContainedBy(
return false;
}

if ($container_type->hasMixed() && !$container_type->isEmptyMixed()) {
return true;
}

$container_has_template = $container_type->hasTemplateOrStatic();

Expand Down
4 changes: 4 additions & 0 deletions tests/TypeComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,9 @@ public function getUnsuccessfulComparisons(): iterable
'list<int>',
'array{int, string}',
];
yield 'nonEmptyMixedDoesNotAcceptMixed' => [
'non-empty-mixed',
'mixed',
];
}
}

0 comments on commit b381f47

Please sign in to comment.