From de9ad68ad07fcedddb518faf501b3a61e53464a4 Mon Sep 17 00:00:00 2001 From: orklah Date: Fri, 5 Nov 2021 20:36:48 +0100 Subject: [PATCH] Mixed contain every types and Never is contained in every type --- .../Type/Comparator/UnionTypeComparator.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php index 43ce5cfeefc..8317b28b193 100644 --- a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php @@ -34,6 +34,14 @@ public static function isContainedBy( bool $allow_interface_equality = false, bool $allow_float_int_equality = true ) : bool { + if ($container_type->isMixed()) { + return true; + } + + if ($input_type->isNever()) { + return true; + } + if ($union_comparison_result) { $union_comparison_result->scalar_type_match_found = true; } @@ -317,6 +325,10 @@ public static function isContainedByInPhp( return false; } + if ($input_type->isNever()) { + return true; + } + if ($input_type->getId() === $container_type->getId()) { return true; } @@ -357,6 +369,10 @@ public static function canBeContainedBy( return true; } + if ($input_type->isNever()) { + return true; + } + if ($input_type->possibly_undefined && !$container_type->possibly_undefined) { return false; }