From d9ebab6b75e94a55e29bc5f683f9f143a2e9b4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Sun, 27 Aug 2023 17:05:13 +0200 Subject: [PATCH] bugfix: prevent infinite-loop when resolving type-aliases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The type-expander returns the same `intersection_type` in case something is not properly expandable. To avoid infinite-loop, we do explicitly verify that the expanded alias is actually resolved Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- src/Psalm/Internal/Type/TypeParser.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/Type/TypeParser.php b/src/Psalm/Internal/Type/TypeParser.php index 35ca41aa2..840d8ea35 100644 --- a/src/Psalm/Internal/Type/TypeParser.php +++ b/src/Psalm/Internal/Type/TypeParser.php @@ -1629,9 +1629,7 @@ class TypeParser continue; } - $modified = true; - - $normalized_intersection_types[] = TypeExpander::expandAtomic( + $expanded_intersection_type = TypeExpander::expandAtomic( $codebase, $intersection_type, null, @@ -1644,6 +1642,9 @@ class TypeParser true, true, ); + + $modified = $expanded_intersection_type[0] !== $intersection_type; + $normalized_intersection_types[] = $expanded_intersection_type; } if ($modified === false) {