Skip to content

Commit

Permalink
Merge pull request #7286 from orklah/classconstinparamout
Browse files Browse the repository at this point in the history
resolve ClassConstant for both sides in isContainedBy
  • Loading branch information
orklah committed Jan 3, 2022
2 parents 13980b5 + 6905dae commit 7227007
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php
Expand Up @@ -84,27 +84,6 @@ public static function isContainedBy(
continue;
}

if ($input_type_part instanceof TClassConstant) {
$expanded = TypeExpander::expandAtomic(
$codebase,
$input_type_part,
$input_type_part->fq_classlike_name,
$input_type_part->fq_classlike_name,
null,
true,
true
);

if ($expanded instanceof Atomic) {
if (!$expanded instanceof TClassConstant) {
$input_atomic_types[] = $expanded;
continue;
}
} else {
$input_atomic_types = array_merge($expanded, $input_atomic_types);
continue;
}
}

$type_match_found = false;
$scalar_type_match_found = false;
Expand Down Expand Up @@ -485,21 +464,30 @@ private static function getTypeParts(
): array {
$atomic_types = [];
foreach ($union_type->getAtomicTypes() as $atomic_type) {
if (!$atomic_type instanceof TTypeAlias) {
if (!$atomic_type instanceof TTypeAlias && !$atomic_type instanceof TClassConstant) {
$atomic_types[] = $atomic_type;
continue;
}

if ($atomic_type instanceof TTypeAlias) {
$fq_classlike_name = $atomic_type->declaring_fq_classlike_name;
} else {
$fq_classlike_name = $atomic_type->fq_classlike_name;
}

$expanded = TypeExpander::expandAtomic(
$codebase,
$atomic_type,
$atomic_type->declaring_fq_classlike_name,
$atomic_type->declaring_fq_classlike_name,
$fq_classlike_name,
$fq_classlike_name,
null,
true,
true
);
if ($expanded instanceof Atomic) {
$atomic_types[] = $expanded;
if (!$expanded instanceof TTypeAlias && !$expanded instanceof TClassConstant) {
$atomic_types[] = $expanded;
}
continue;
}

Expand Down

0 comments on commit 7227007

Please sign in to comment.