Skip to content

Commit d220ce8

Browse files
committed
Reorder execution and expand comment
1 parent 6033e39 commit d220ce8

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
@@ -611,11 +611,11 @@ static inheritance_status zend_perform_covariant_type_check(
611611
zend_type *single_type;
612612
bool all_success = true;
613613

614-
/* For intersection types loop over the parent types first as a child
615-
* can add them */
616-
if (ZEND_TYPE_IS_INTERSECTION(fe_type)
617-
|| (ZEND_TYPE_IS_INTERSECTION(proto_type) && !ZEND_TYPE_IS_UNION(fe_type))
618-
) {
614+
/* If the child type is an intersection type then we need to loop over
615+
* the parents firstFor intersection types loop over the parent types first
616+
* as the child can add types, however none of them can be a supertype of
617+
* a parent type. */
618+
if (ZEND_TYPE_IS_INTERSECTION(fe_type)) {
619619
/* First try to check whether we can succeed without resolving anything */
620620
ZEND_TYPE_FOREACH(proto_type, single_type) {
621621
inheritance_status status;
@@ -645,13 +645,12 @@ static inheritance_status zend_perform_covariant_type_check(
645645
all_success = false;
646646
}
647647
} ZEND_TYPE_FOREACH_END();
648-
} else if (ZEND_TYPE_IS_INTERSECTION(proto_type) && ZEND_TYPE_IS_UNION(fe_type)) {
649-
/* Here each member of the child union must be a subtype of the intersection */
648+
} else if (ZEND_TYPE_IS_INTERSECTION(proto_type)) {
649+
/* Here each member of the child union must be a subtype of the intersection
650+
* Note: the union can be a single element */
650651

651652
/* First try to check whether we can succeed without resolving anything */
652-
zend_type_list *child_union_types = ZEND_TYPE_LIST(fe_type);
653-
654-
ZEND_TYPE_LIST_FOREACH(child_union_types, single_type) {
653+
ZEND_TYPE_FOREACH(fe_type, single_type) {
655654
inheritance_status status;
656655
zend_string *fe_class_name;
657656
zend_class_entry *fe_ce = NULL;
@@ -677,7 +676,7 @@ static inheritance_status zend_perform_covariant_type_check(
677676
if (status != INHERITANCE_SUCCESS) {
678677
all_success = false;
679678
}
680-
} ZEND_TYPE_LIST_FOREACH_END();
679+
} ZEND_TYPE_FOREACH_END();
681680
}
682681
/* Only union or single types both in parent and child */
683682
else {

0 commit comments

Comments
 (0)