Skip to content

Commit 29e1a9d

Browse files
committed
Reorder execution and expand comment
1 parent 61ee393 commit 29e1a9d

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
@@ -575,11 +575,11 @@ static inheritance_status zend_perform_covariant_type_check(
575575
zend_type *single_type;
576576
bool all_success = true;
577577

578-
/* For intersection types loop over the parent types first as a child
579-
* can add them */
580-
if (ZEND_TYPE_IS_INTERSECTION(fe_type)
581-
|| (ZEND_TYPE_IS_INTERSECTION(proto_type) && !ZEND_TYPE_IS_UNION(fe_type))
582-
) {
578+
/* If the child type is an intersection type then we need to loop over
579+
* the parents firstFor intersection types loop over the parent types first
580+
* as the child can add types, however none of them can be a supertype of
581+
* a parent type. */
582+
if (ZEND_TYPE_IS_INTERSECTION(fe_type)) {
583583
/* First try to check whether we can succeed without resolving anything */
584584
ZEND_TYPE_FOREACH(proto_type, single_type) {
585585
inheritance_status status;
@@ -609,13 +609,12 @@ static inheritance_status zend_perform_covariant_type_check(
609609
all_success = false;
610610
}
611611
} ZEND_TYPE_FOREACH_END();
612-
} else if (ZEND_TYPE_IS_INTERSECTION(proto_type) && ZEND_TYPE_IS_UNION(fe_type)) {
613-
/* Here each member of the child union must be a subtype of the intersection */
612+
} else if (ZEND_TYPE_IS_INTERSECTION(proto_type)) {
613+
/* Here each member of the child union must be a subtype of the intersection
614+
* Note: the union can be a single element */
614615

615616
/* First try to check whether we can succeed without resolving anything */
616-
zend_type_list *child_union_types = ZEND_TYPE_LIST(fe_type);
617-
618-
ZEND_TYPE_LIST_FOREACH(child_union_types, single_type) {
617+
ZEND_TYPE_FOREACH(fe_type, single_type) {
619618
inheritance_status status;
620619
zend_string *fe_class_name;
621620
zend_class_entry *fe_ce = NULL;
@@ -641,7 +640,7 @@ static inheritance_status zend_perform_covariant_type_check(
641640
if (status != INHERITANCE_SUCCESS) {
642641
all_success = false;
643642
}
644-
} ZEND_TYPE_LIST_FOREACH_END();
643+
} ZEND_TYPE_FOREACH_END();
645644
}
646645
/* Only union or single types both in parent and child */
647646
else {

0 commit comments

Comments
 (0)