@@ -1230,12 +1230,7 @@ zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scop
1230
1230
/* Pure intersection type */
1231
1231
if (ZEND_TYPE_IS_INTERSECTION (type )) {
1232
1232
ZEND_ASSERT (!ZEND_TYPE_IS_UNION (type ));
1233
- bool is_bracketed = false;
1234
- /* Shim for implicitly nullable pure intersection types */
1235
- if (UNEXPECTED (ZEND_TYPE_PURE_MASK (type ) & MAY_BE_NULL )) {
1236
- is_bracketed = true;
1237
- }
1238
- str = add_intersection_type (str , ZEND_TYPE_LIST (type ), scope , is_bracketed );
1233
+ str = add_intersection_type (str , ZEND_TYPE_LIST (type ), scope , /* is_bracketed */ false);
1239
1234
} else if (ZEND_TYPE_HAS_LIST (type )) {
1240
1235
/* A union type might not be a list */
1241
1236
zend_type * list_type ;
@@ -6528,10 +6523,24 @@ static zend_type zend_compile_typename(
6528
6523
6529
6524
ZEND_ASSERT (list -> children == type_list -> num_types );
6530
6525
6531
- ZEND_TYPE_SET_LIST (type , type_list );
6532
6526
ZEND_TYPE_FULL_MASK (type ) |= _ZEND_TYPE_ARENA_BIT ;
6533
- /* Inform that the type list is an intersection type */
6534
- ZEND_TYPE_FULL_MASK (type ) |= _ZEND_TYPE_INTERSECTION_BIT ;
6527
+ /* An implicitly nullable intersection type needs to be converted to a DNF type */
6528
+ if (force_allow_null ) {
6529
+ zend_type intersection_type = ZEND_TYPE_INIT_NONE (0 );
6530
+ ZEND_TYPE_SET_LIST (intersection_type , type_list );
6531
+ ZEND_TYPE_FULL_MASK (intersection_type ) |= _ZEND_TYPE_INTERSECTION_BIT ;
6532
+
6533
+ zend_type_list * dnf_type_list = zend_arena_alloc (& CG (arena ), ZEND_TYPE_LIST_SIZE (list -> children ));
6534
+ dnf_type_list -> num_types = 1 ;
6535
+ dnf_type_list -> types [0 ] = intersection_type ;
6536
+ ZEND_TYPE_SET_LIST (type , dnf_type_list );
6537
+ /* Inform that the type list is a DNF type */
6538
+ ZEND_TYPE_FULL_MASK (type ) |= _ZEND_TYPE_UNION_BIT ;
6539
+ } else {
6540
+ ZEND_TYPE_SET_LIST (type , type_list );
6541
+ /* Inform that the type list is an intersection type */
6542
+ ZEND_TYPE_FULL_MASK (type ) |= _ZEND_TYPE_INTERSECTION_BIT ;
6543
+ }
6535
6544
} else {
6536
6545
type = zend_compile_single_typename (ast );
6537
6546
}
0 commit comments