Skip to content

Commit

Permalink
Merge pull request #8794 from danog/fix_8772
Browse files Browse the repository at this point in the history
Ignore non-existing classes during initial scan of intersection types
  • Loading branch information
orklah committed Nov 30, 2022
2 parents 870f581 + 9c35ed2 commit ea4fe74
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Psalm/Type.php
Expand Up @@ -850,12 +850,16 @@ private static function intersectAtomicTypes(
) {
/** @psalm-suppress TypeDoesNotContainType */
if ($type_1_atomic instanceof TNamedObject && $type_2_atomic instanceof TNamedObject) {
$first = $codebase->classlike_storage_provider->get($type_1_atomic->value);
$second = $codebase->classlike_storage_provider->get($type_2_atomic->value);
$first_is_class = !$first->is_interface && !$first->is_trait;
$second_is_class = !$second->is_interface && !$second->is_trait;
if ($first_is_class && $second_is_class) {
return $intersection_atomic;
try {
$first = $codebase->classlike_storage_provider->get($type_1_atomic->value);
$second = $codebase->classlike_storage_provider->get($type_2_atomic->value);
$first_is_class = !$first->is_interface && !$first->is_trait;
$second_is_class = !$second->is_interface && !$second->is_trait;
if ($first_is_class && $second_is_class) {
return $intersection_atomic;
}
} catch (InvalidArgumentException $e) {
// Ignore non-existing classes during initial scan
}
}
if ($intersection_atomic === null && $wider_type === null) {
Expand Down Expand Up @@ -914,7 +918,12 @@ private static function mayHaveIntersection(Atomic $type, Codebase $codebase): b
if (!$type instanceof TNamedObject) {
return false;
}
$storage = $codebase->classlike_storage_provider->get($type->value);
try {
$storage = $codebase->classlike_storage_provider->get($type->value);
} catch (InvalidArgumentException $e) {
// Ignore non-existing classes during initial scan
return true;
}
return !$storage->final;
}

Expand Down

0 comments on commit ea4fe74

Please sign in to comment.