From 7bd35be5d5f70b73f7eab5768e4c9931aff85a75 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Mon, 19 Feb 2024 01:41:19 +0100 Subject: [PATCH] Catch missing classlike exceptions during scanning This may resolve #10706, although I'm not exactly convinced it's the best way. --- src/Psalm/Type.php | 56 +++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/Psalm/Type.php b/src/Psalm/Type.php index cc5de1f8b03..793c3198b2e 100644 --- a/src/Psalm/Type.php +++ b/src/Psalm/Type.php @@ -888,33 +888,37 @@ private static function intersectAtomicTypes( } if (null === $intersection_atomic) { - if (AtomicTypeComparator::isContainedBy( - $codebase, - $type_2_atomic, - $type_1_atomic, - $allow_interface_equality, - $allow_float_int_equality, - )) { - $intersection_atomic = $type_2_atomic; - $wider_type = $type_1_atomic; - $intersection_performed = true; - } elseif (AtomicTypeComparator::isContainedBy( - $codebase, - $type_1_atomic, - $type_2_atomic, - $allow_interface_equality, - $allow_float_int_equality, - )) { - $intersection_atomic = $type_1_atomic; - $wider_type = $type_2_atomic; - $intersection_performed = true; - } + try { + if (AtomicTypeComparator::isContainedBy( + $codebase, + $type_2_atomic, + $type_1_atomic, + $allow_interface_equality, + $allow_float_int_equality, + )) { + $intersection_atomic = $type_2_atomic; + $wider_type = $type_1_atomic; + $intersection_performed = true; + } elseif (AtomicTypeComparator::isContainedBy( + $codebase, + $type_1_atomic, + $type_2_atomic, + $allow_interface_equality, + $allow_float_int_equality, + )) { + $intersection_atomic = $type_1_atomic; + $wider_type = $type_2_atomic; + $intersection_performed = true; + } - if ($intersection_atomic - && !self::hasIntersection($type_1_atomic) - && !self::hasIntersection($type_2_atomic) - ) { - return $intersection_atomic; + if ($intersection_atomic + && !self::hasIntersection($type_1_atomic) + && !self::hasIntersection($type_2_atomic) + ) { + return $intersection_atomic; + } + } catch (InvalidArgumentException $e) { + // Ignore non-existing classes during initial scan } }