Skip to content

Commit

Permalink
bugfix: prevent infinite-loop when resolving type-aliases
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
boesing committed Aug 27, 2023
1 parent 77436b1 commit 58b55d0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Psalm/Internal/Type/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1629,9 +1629,7 @@ private static function resolveTypeAliases(Codebase $codebase, array $intersecti
continue;
}

$modified = true;

$normalized_intersection_types[] = TypeExpander::expandAtomic(
$expanded_intersection_type = TypeExpander::expandAtomic(
$codebase,
$intersection_type,
null,
Expand All @@ -1644,6 +1642,9 @@ private static function resolveTypeAliases(Codebase $codebase, array $intersecti
true,
true,
);

$modified = $normalized_intersection_types[0] !== $intersection_type;

Check failure on line 1646 in src/Psalm/Internal/Type/TypeParser.php

View workflow job for this annotation

GitHub Actions / build

PossiblyUndefinedArrayOffset

src/Psalm/Internal/Type/TypeParser.php:1646:25: PossiblyUndefinedArrayOffset: Possibly undefined array key $normalized_intersection_types[0] on list{0?: list{Psalm\Type\Atomic, ...<Psalm\Type\Atomic>}, ...<list{Psalm\Type\Atomic, ...<Psalm\Type\Atomic>}>} (see https://psalm.dev/167)

Check failure on line 1646 in src/Psalm/Internal/Type/TypeParser.php

View workflow job for this annotation

GitHub Actions / build

RedundantCondition

src/Psalm/Internal/Type/TypeParser.php:1646:25: RedundantCondition: list{Psalm\Type\Atomic, ...<Psalm\Type\Atomic>} can never contain Psalm\Type\Atomic (see https://psalm.dev/122)
$normalized_intersection_types[] = $expanded_intersection_type;
}

if ($modified === false) {
Expand Down

0 comments on commit 58b55d0

Please sign in to comment.