Skip to content

Commit 1747fa9

Browse files
phpstan-botclaude
andcommitted
Check for IntersectionType before calling isConstantScalarValue() in TypeCombinator::union()
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 22b0b9f commit 1747fa9

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

‎src/Type/TypeCombinator.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public static function doUnion(Type ...$types): Type
423423
// a constant scalar refined by an accessory type ('Foo'&hasMethod(bar))
424424
// stays with the other types so it is compared against the plain
425425
// constant scalars and other refinements of the same value
426-
if ($types[$i]->isConstantScalarValue()->yes() && !$types[$i] instanceof IntersectionType) {
426+
if (!$types[$i] instanceof IntersectionType && $types[$i]->isConstantScalarValue()->yes()) {
427427
$type = $types[$i];
428428
$scalarTypes[get_class($type)][$type->describe(VerbosityLevel::cache())] = $type;
429429
unset($types[$i]);

‎turbo-ext/src/TypeCombinator.cpp‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,9 +1038,12 @@ class TypeCombinator
10381038
Level cacheLevel(PT_LC("cache"));
10391039
for (size_t i = 0; i < typesCount; i++) {
10401040
zval *type = types[i].raw();
1041-
zend_long isConstantScalarValue = callTrinary(type, PT_LC("isconstantscalarvalue"));
1042-
PT_FAIL_IF_NEG(isConstantScalarValue);
1043-
if (isConstantScalarValue == PT_TRI_YES && !isInstance(type, pt_ce_intersection_type)) {
1041+
zend_long isConstantScalarValue = PT_TRI_NO;
1042+
if (!isInstance(type, pt_ce_intersection_type)) {
1043+
isConstantScalarValue = callTrinary(type, PT_LC("isconstantscalarvalue"));
1044+
PT_FAIL_IF_NEG(isConstantScalarValue);
1045+
}
1046+
if (isConstantScalarValue == PT_TRI_YES) {
10441047
zv::Val description = describe(type, cacheLevel);
10451048
zend_string *key = describedKey(description);
10461049
if (UNEXPECTED(key == NULL)) return zv::Val();

0 commit comments

Comments
 (0)