Skip to content

Commit 062d557

Browse files
committed
Reorder execution and expand comment
1 parent 2d30485 commit 062d557

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

Zend/zend_inheritance.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,11 @@ static inheritance_status zend_perform_covariant_type_check(
623623
zend_type *single_type;
624624
bool all_success = true;
625625

626-
/* For intersection types loop over the parent types first as a child
627-
* can add them */
628-
if (ZEND_TYPE_IS_INTERSECTION(fe_type)
629-
|| (ZEND_TYPE_IS_INTERSECTION(proto_type) && !ZEND_TYPE_IS_UNION(fe_type))
630-
) {
626+
/* If the child type is an intersection type then we need to loop over
627+
* the parents firstFor intersection types loop over the parent types first
628+
* as the child can add types, however none of them can be a supertype of
629+
* a parent type. */
630+
if (ZEND_TYPE_IS_INTERSECTION(fe_type)) {
631631
/* First try to check whether we can succeed without resolving anything */
632632
ZEND_TYPE_FOREACH(proto_type, single_type) {
633633
inheritance_status status;
@@ -657,13 +657,12 @@ static inheritance_status zend_perform_covariant_type_check(
657657
all_success = false;
658658
}
659659
} ZEND_TYPE_FOREACH_END();
660-
} else if (ZEND_TYPE_IS_INTERSECTION(proto_type) && ZEND_TYPE_IS_UNION(fe_type)) {
661-
/* Here each member of the child union must be a subtype of the intersection */
660+
} else if (ZEND_TYPE_IS_INTERSECTION(proto_type)) {
661+
/* Here each member of the child union must be a subtype of the intersection
662+
* Note: the union can be a single element */
662663

663664
/* First try to check whether we can succeed without resolving anything */
664-
zend_type_list *child_union_types = ZEND_TYPE_LIST(fe_type);
665-
666-
ZEND_TYPE_LIST_FOREACH(child_union_types, single_type) {
665+
ZEND_TYPE_FOREACH(fe_type, single_type) {
667666
inheritance_status status;
668667
zend_string *fe_class_name;
669668
zend_class_entry *fe_ce = NULL;
@@ -689,7 +688,7 @@ static inheritance_status zend_perform_covariant_type_check(
689688
if (status != INHERITANCE_SUCCESS) {
690689
all_success = false;
691690
}
692-
} ZEND_TYPE_LIST_FOREACH_END();
691+
} ZEND_TYPE_FOREACH_END();
693692
}
694693
/* Only union or single types both in parent and child */
695694
else {

0 commit comments

Comments
 (0)