Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Jan 16, 2026

first found of fixes to get TypeCombinator::union() / intersect() ready for no-named-arguments

* @param Type[] $types
* @return Type[]
* @template T of Type
* @param list<T>|array<T> $types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list<T>|array<T> does not make sense, should be just array<T>. The return type condition would still work.

But could we instead always make sure that list is passed here?

Copy link
Contributor Author

@staabm staabm Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But could we instead always make sure that list is passed here?

to make that work I either need to ignore some errors, or narrow the constructor parameters of e.g. UnionType, IntersectionType etc. (which you might not want because BC break)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did the change, please have a look whether you like it

Comment on lines 381 to 392
if ($tempTypes === []) {
if ($benevolentUnionObject instanceof TemplateBenevolentUnionType) {
return $benevolentUnionObject->withTypes($types);
return $benevolentUnionObject->withTypes(array_values($types));
}

return new BenevolentUnionType($types, true);
return new BenevolentUnionType(array_values($types), true);
}
}

return new UnionType($types, true);
return new UnionType(array_values($types), true);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might phpdoc-cast this parameter instead of doing a runtime array_values to reduce overhead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants