Skip to content

Commit

Permalink
Prevent infinite loop in case a TClassConstant is expanded to itself (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
orklah authored Jun 18, 2021
1 parent 79478a6 commit 3c9476b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2076,11 +2076,13 @@ private static function checkArrayOffsetType(
);

if ($expanded instanceof Atomic) {
$has_valid_absolute_offset = self::checkArrayOffsetType(
$offset_type,
[$expanded],
$codebase
);
if (!$expanded instanceof Atomic\TClassConstant) {
$has_valid_absolute_offset = self::checkArrayOffsetType(
$offset_type,
[$expanded],
$codebase
);
}
} else {
$has_valid_absolute_offset = self::checkArrayOffsetType(
$offset_type,
Expand Down
8 changes: 5 additions & 3 deletions src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ public static function isContainedBy(
);

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

continue;
}

$type_match_found = false;
Expand Down

0 comments on commit 3c9476b

Please sign in to comment.