@@ -6306,6 +6306,8 @@ static zend_type zend_compile_typename(
6306
6306
type_list = do_alloca (ZEND_TYPE_LIST_SIZE (list -> children ), use_heap );
6307
6307
type_list -> num_types = 0 ;
6308
6308
6309
+ ZEND_ASSERT (list -> children > 1 );
6310
+
6309
6311
for (uint32_t i = 0 ; i < list -> children ; i ++ ) {
6310
6312
zend_ast * type_ast = list -> child [i ];
6311
6313
zend_type single_type = zend_compile_single_typename (type_ast );
@@ -6324,42 +6326,30 @@ static zend_type zend_compile_typename(
6324
6326
}
6325
6327
zend_string_release_ex (standard_type_str , false);
6326
6328
6327
- if (!ZEND_TYPE_IS_COMPLEX (type )) {
6328
- /* The first class type can be stored directly as the type ptr payload. */
6329
- ZEND_TYPE_SET_PTR (type , ZEND_TYPE_NAME (single_type ));
6330
- ZEND_TYPE_FULL_MASK (type ) |= _ZEND_TYPE_NAME_BIT ;
6331
- } else {
6332
- if (type_list -> num_types == 0 ) {
6333
- /* Switch from single name to name list. */
6334
- type_list -> num_types = 1 ;
6335
- type_list -> types [0 ] = type ;
6336
- ZEND_TYPE_FULL_MASK (type_list -> types [0 ]) &= ~_ZEND_TYPE_MAY_BE_MASK ;
6337
- ZEND_TYPE_SET_LIST (type , type_list );
6338
- }
6339
-
6340
- type_list -> types [type_list -> num_types ++ ] = single_type ;
6329
+ /* Add type to the type list */
6330
+ type_list -> types [type_list -> num_types ++ ] = single_type ;
6341
6331
6342
- /* Check for trivially redundant class types */
6343
- for (size_t i = 0 ; i < type_list -> num_types - 1 ; i ++ ) {
6344
- if (zend_string_equals_ci (
6345
- ZEND_TYPE_NAME (type_list -> types [i ]), ZEND_TYPE_NAME (single_type ))) {
6346
- zend_string * single_type_str = zend_type_to_string (single_type );
6347
- zend_error_noreturn (E_COMPILE_ERROR ,
6348
- "Duplicate type %s is redundant" , ZSTR_VAL (single_type_str ));
6349
- }
6332
+ /* Check for trivially redundant class types */
6333
+ for (size_t i = 0 ; i < type_list -> num_types - 1 ; i ++ ) {
6334
+ if (zend_string_equals_ci (
6335
+ ZEND_TYPE_NAME (type_list -> types [i ]), ZEND_TYPE_NAME (single_type ))) {
6336
+ zend_string * single_type_str = zend_type_to_string (single_type );
6337
+ zend_error_noreturn (E_COMPILE_ERROR ,
6338
+ "Duplicate type %s is redundant" , ZSTR_VAL (single_type_str ));
6350
6339
}
6351
6340
}
6352
6341
}
6353
6342
6354
- if (type_list -> num_types ) {
6355
- zend_type_list * list = zend_arena_alloc (
6356
- & CG (arena ), ZEND_TYPE_LIST_SIZE (type_list -> num_types ));
6357
- memcpy (list , type_list , ZEND_TYPE_LIST_SIZE (type_list -> num_types ));
6358
- ZEND_TYPE_SET_LIST (type , list );
6359
- ZEND_TYPE_FULL_MASK (type ) |= _ZEND_TYPE_ARENA_BIT ;
6360
- /* Inform that the type list is an intersection type */
6361
- ZEND_TYPE_FULL_MASK (type ) |= _ZEND_TYPE_INTERSECTION_BIT ;
6362
- }
6343
+ ZEND_ASSERT (type_list -> num_types > 1 );
6344
+
6345
+ /* TODO Can be arena allocated directly? */
6346
+ zend_type_list * reduced_list = zend_arena_alloc (
6347
+ & CG (arena ), ZEND_TYPE_LIST_SIZE (type_list -> num_types ));
6348
+ memcpy (reduced_list , type_list , ZEND_TYPE_LIST_SIZE (type_list -> num_types ));
6349
+ ZEND_TYPE_SET_LIST (type , reduced_list );
6350
+ ZEND_TYPE_FULL_MASK (type ) |= _ZEND_TYPE_ARENA_BIT ;
6351
+ /* Inform that the type list is an intersection type */
6352
+ ZEND_TYPE_FULL_MASK (type ) |= _ZEND_TYPE_INTERSECTION_BIT ;
6363
6353
6364
6354
free_alloca (type_list , use_heap );
6365
6355
} else {
0 commit comments