diff --git a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php index f0303e362d5..c997199d650 100644 --- a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php @@ -362,7 +362,7 @@ public static function canBeContainedBy( return false; } - foreach ($container_type->getAtomicTypes() as $container_type_part) { + foreach (self::getTypeParts($codebase, $container_type) as $container_type_part) { if ($container_type_part instanceof TNull && $ignore_null) { continue; } @@ -371,7 +371,7 @@ public static function canBeContainedBy( continue; } - foreach ($input_type->getAtomicTypes() as $input_type_part) { + foreach (self::getTypeParts($codebase, $input_type) as $input_type_part) { $atomic_comparison_result = new TypeComparisonResult(); $is_atomic_contained_by = AtomicTypeComparator::isContainedBy( $codebase, @@ -411,8 +411,8 @@ public static function canExpressionTypesBeIdentical( return true; } - foreach ($type1->getAtomicTypes() as $type1_part) { - foreach ($type2->getAtomicTypes() as $type2_part) { + foreach (self::getTypeParts($codebase, $type1) as $type1_part) { + foreach (self::getTypeParts($codebase, $type2) as $type2_part) { //special cases for TIntRange because it can contain a part of the other type. //For exemple int<0,1> and positive-int can be identical but none contain the other if (($type1_part instanceof TIntRange && $type2_part instanceof TPositiveInt)) { diff --git a/tests/ConstantTest.php b/tests/ConstantTest.php index 1aefeb093bc..22250503f13 100644 --- a/tests/ConstantTest.php +++ b/tests/ConstantTest.php @@ -1200,6 +1200,36 @@ class C { [], '8.1' ], + 'classConstWithParamOut' => [ + '