@@ -2709,46 +2709,53 @@ void zend_compile_static_prop(znode *result, zend_ast *ast, uint32_t type, int d
27092709}
27102710/* }}} */
27112711
2712- static void zend_compile_list_assign ( znode * result , zend_ast * ast , znode * expr_node ) /* {{{ */
2712+ static void zend_compile_unkeyed_list_assign ( zend_ast_list * list , znode * expr_node ) /* {{{ */
27132713{
2714- zend_ast_list * list = zend_ast_get_list (ast );
27152714 uint32_t i ;
2716- zend_ulong next_index = 0 ;
27172715 zend_bool has_elems = 0 ;
27182716
27192717 for (i = 0 ; i < list -> children ; ++ i ) {
2720- zend_ast * pair_ast = list -> child [i ];
2721- zend_ast * var_ast ;
2722- zend_ast * key_ast ;
2718+ zend_ast * var_ast = list -> child [i ];
27232719 znode fetch_result , dim_node ;
27242720
2725- if (pair_ast == NULL ) {
2726- next_index ++ ;
2721+ if (var_ast == NULL ) {
27272722 continue ;
27282723 }
2724+ has_elems = 1 ;
27292725
2730- var_ast = pair_ast -> child [ 0 ] ;
2731- key_ast = pair_ast -> child [ 1 ] ;
2726+ dim_node . op_type = IS_CONST ;
2727+ ZVAL_LONG ( & dim_node . u . constant , i ) ;
27322728
2733- if (key_ast ) {
2734- zend_compile_expr ( & dim_node , key_ast );
2735- zend_handle_numeric_op ( & dim_node );
2729+ if (expr_node -> op_type == IS_CONST ) {
2730+ Z_TRY_ADDREF ( expr_node -> u . constant );
2731+ }
27362732
2737- if (Z_TYPE (dim_node .u .constant ) != IS_LONG && Z_TYPE (dim_node .u .constant ) != IS_STRING ) {
2738- zend_error_noreturn (E_COMPILE_ERROR , "Key must be an integer or string literal" );
2739- }
2740-
2741- if (Z_TYPE (dim_node .u .constant ) == IS_LONG ) {
2742- next_index = Z_LVAL (dim_node .u .constant );
2743- }
2744- } else {
2745- dim_node .op_type = IS_CONST ;
2746- ZVAL_LONG (& dim_node .u .constant , next_index );
2733+ zend_emit_op (& fetch_result , ZEND_FETCH_LIST , expr_node , & dim_node );
2734+ zend_emit_assign_znode (var_ast , & fetch_result );
2735+ }
27472736
2748- next_index ++ ;
2749- }
2737+ if (!has_elems ) {
2738+ zend_error_noreturn (E_COMPILE_ERROR , "Cannot use empty list" );
2739+ }
2740+ }
2741+ /* }}} */
27502742
2751- has_elems = 1 ;
2743+ static void zend_compile_keyed_list_assign (zend_ast_list * list , znode * expr_node ) /* {{{ */
2744+ {
2745+ uint32_t i ;
2746+
2747+ for (i = 0 ; i < list -> children ; ++ i ) {
2748+ zend_ast * pair_ast = list -> child [i ];
2749+ zend_ast * var_ast = pair_ast -> child [0 ];
2750+ zend_ast * key_ast = pair_ast -> child [1 ];
2751+ znode fetch_result , dim_node ;
2752+
2753+ zend_compile_expr (& dim_node , key_ast );
2754+ zend_handle_numeric_op (& dim_node );
2755+
2756+ if (Z_TYPE (dim_node .u .constant ) != IS_LONG && Z_TYPE (dim_node .u .constant ) != IS_STRING ) {
2757+ zend_error_noreturn (E_COMPILE_ERROR , "Key must be an integer or string literal" );
2758+ }
27522759
27532760 if (expr_node -> op_type == IS_CONST ) {
27542761 Z_TRY_ADDREF (expr_node -> u .constant );
@@ -2757,9 +2764,17 @@ static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_n
27572764 zend_emit_op (& fetch_result , ZEND_FETCH_LIST , expr_node , & dim_node );
27582765 zend_emit_assign_znode (var_ast , & fetch_result );
27592766 }
2767+ }
2768+ /* }}} */
27602769
2761- if (!has_elems ) {
2762- zend_error_noreturn (E_COMPILE_ERROR , "Cannot use empty list" );
2770+ static void zend_compile_list_assign (znode * result , zend_ast * ast , znode * expr_node ) /* {{{ */
2771+ {
2772+ zend_ast_list * list = zend_ast_get_list (ast );
2773+
2774+ if (list -> children > 0 && list -> child [0 ] != NULL && list -> child [0 ]-> kind == ZEND_AST_ARRAY_ELEM ) {
2775+ zend_compile_keyed_list_assign (list , expr_node );
2776+ } else {
2777+ zend_compile_unkeyed_list_assign (list , expr_node );
27632778 }
27642779
27652780 * result = * expr_node ;
0 commit comments