Skip to content

Commit 3c9476b

Browse files
authored
Prevent infinite loop in case a TClassConstant is expanded to itself (#5951)
1 parent 79478a6 commit 3c9476b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -2076,11 +2076,13 @@ private static function checkArrayOffsetType(
20762076
);
20772077

20782078
if ($expanded instanceof Atomic) {
2079-
$has_valid_absolute_offset = self::checkArrayOffsetType(
2080-
$offset_type,
2081-
[$expanded],
2082-
$codebase
2083-
);
2079+
if (!$expanded instanceof Atomic\TClassConstant) {
2080+
$has_valid_absolute_offset = self::checkArrayOffsetType(
2081+
$offset_type,
2082+
[$expanded],
2083+
$codebase
2084+
);
2085+
}
20842086
} else {
20852087
$has_valid_absolute_offset = self::checkArrayOffsetType(
20862088
$offset_type,

src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ public static function isContainedBy(
8181
);
8282

8383
if ($expanded instanceof Atomic) {
84-
$input_atomic_types[] = $expanded;
84+
if (!$expanded instanceof Atomic\TClassConstant) {
85+
$input_atomic_types[] = $expanded;
86+
continue;
87+
}
8588
} else {
8689
$input_atomic_types = array_merge($expanded, $input_atomic_types);
90+
continue;
8791
}
88-
89-
continue;
9092
}
9193

9294
$type_match_found = false;

0 commit comments

Comments
 (0)