@@ -575,11 +575,11 @@ static inheritance_status zend_perform_covariant_type_check(
575
575
zend_type * single_type ;
576
576
bool all_success = true;
577
577
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 ) ) {
583
583
/* First try to check whether we can succeed without resolving anything */
584
584
ZEND_TYPE_FOREACH (proto_type , single_type ) {
585
585
inheritance_status status ;
@@ -609,13 +609,12 @@ static inheritance_status zend_perform_covariant_type_check(
609
609
all_success = false;
610
610
}
611
611
} 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 */
614
615
615
616
/* 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 ) {
619
618
inheritance_status status ;
620
619
zend_string * fe_class_name ;
621
620
zend_class_entry * fe_ce = NULL ;
@@ -641,7 +640,7 @@ static inheritance_status zend_perform_covariant_type_check(
641
640
if (status != INHERITANCE_SUCCESS ) {
642
641
all_success = false;
643
642
}
644
- } ZEND_TYPE_LIST_FOREACH_END ();
643
+ } ZEND_TYPE_FOREACH_END ();
645
644
}
646
645
/* Only union or single types both in parent and child */
647
646
else {
0 commit comments