Skip to content

Commit

Permalink
Merge pull request #7288 from orklah/classconst4
Browse files Browse the repository at this point in the history
resolve type alias and class const on UnionTypeComparator
  • Loading branch information
orklah committed Jan 3, 2022
2 parents 4d5098f + 6f9cbc6 commit 68e50f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down
30 changes: 30 additions & 0 deletions tests/ConstantTest.php
Expand Up @@ -1200,6 +1200,36 @@ class C {
[],
'8.1'
],
'classConstWithParamOut' => [
'<?php
class Reconciler
{
public const RECONCILIATION_OK = 0;
public const RECONCILIATION_EMPTY = 1;
public static function reconcileKeyedTypes(): void
{
$failed_reconciliation = 0;
self::boo($failed_reconciliation);
if ($failed_reconciliation === self::RECONCILIATION_EMPTY) {
echo "ici";
}
}
/** @param-out Reconciler::RECONCILIATION_* $f */
public static function boo(
?int &$f = self::RECONCILIATION_OK
): void {
$f = self::RECONCILIATION_EMPTY;
}
}
Reconciler::reconcileKeyedTypes();
',
],
];
}

Expand Down

0 comments on commit 68e50f5

Please sign in to comment.