@@ -623,11 +623,11 @@ static inheritance_status zend_perform_covariant_type_check(
623
623
zend_type * single_type ;
624
624
bool all_success = true;
625
625
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 ) ) {
631
631
/* First try to check whether we can succeed without resolving anything */
632
632
ZEND_TYPE_FOREACH (proto_type , single_type ) {
633
633
inheritance_status status ;
@@ -657,13 +657,12 @@ static inheritance_status zend_perform_covariant_type_check(
657
657
all_success = false;
658
658
}
659
659
} 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 */
662
663
663
664
/* 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 ) {
667
666
inheritance_status status ;
668
667
zend_string * fe_class_name ;
669
668
zend_class_entry * fe_ce = NULL ;
@@ -689,7 +688,7 @@ static inheritance_status zend_perform_covariant_type_check(
689
688
if (status != INHERITANCE_SUCCESS ) {
690
689
all_success = false;
691
690
}
692
- } ZEND_TYPE_LIST_FOREACH_END ();
691
+ } ZEND_TYPE_FOREACH_END ();
693
692
}
694
693
/* Only union or single types both in parent and child */
695
694
else {
0 commit comments