@@ -6375,18 +6375,6 @@ static void zend_compile_switch(zend_ast *ast) /* {{{ */
6375
6375
}
6376
6376
/* }}} */
6377
6377
6378
- static bool do_match_conditions_contain_default (zend_ast_list * conditions )
6379
- {
6380
- for (uint32_t i = 0 ; i < conditions -> children ; ++ i ) {
6381
- // Default as an expression is still allowed, so we don't need to recurse sub-lists.
6382
- if (conditions -> child [i ]-> kind == ZEND_AST_DEFAULT ) {
6383
- return true;
6384
- }
6385
- }
6386
-
6387
- return false;
6388
- }
6389
-
6390
6378
static uint32_t count_match_conds (zend_ast_list * arms )
6391
6379
{
6392
6380
uint32_t num_conds = 0 ;
@@ -6395,7 +6383,7 @@ static uint32_t count_match_conds(zend_ast_list *arms)
6395
6383
zend_ast * arm_ast = arms -> child [i ];
6396
6384
zend_ast_list * conds = zend_ast_get_list (arm_ast -> child [0 ]);
6397
6385
6398
- if (do_match_conditions_contain_default ( conds ) ) {
6386
+ if (conds -> child [ 0 ] -> kind == ZEND_AST_DEFAULT ) {
6399
6387
continue ;
6400
6388
}
6401
6389
@@ -6410,7 +6398,7 @@ static bool can_match_use_jumptable(zend_ast_list *arms) {
6410
6398
zend_ast * arm_ast = arms -> child [i ];
6411
6399
zend_ast_list * conds = zend_ast_get_list (arm_ast -> child [0 ]);
6412
6400
6413
- if (do_match_conditions_contain_default ( conds ) ) {
6401
+ if (conds -> child [ 0 ] -> kind == ZEND_AST_DEFAULT ) {
6414
6402
/* Skip default arm */
6415
6403
continue ;
6416
6404
}
@@ -6457,13 +6445,20 @@ static void zend_compile_match(znode *result, zend_ast *ast)
6457
6445
zend_ast * arm_ast = arms -> child [i ];
6458
6446
zend_ast_list * conds = zend_ast_get_list (arm_ast -> child [0 ]);
6459
6447
6460
- if (do_match_conditions_contain_default (conds )) {
6461
- if (has_default_arm ) {
6462
- CG (zend_lineno ) = arm_ast -> lineno ;
6463
- zend_error_noreturn (E_COMPILE_ERROR ,
6464
- "Match expressions may only contain one default arm" );
6448
+ for (uint32_t j = 0 ; j < conds -> children ; ++ j ) {
6449
+ if (conds -> child [j ]-> kind == ZEND_AST_DEFAULT ) {
6450
+ if (conds -> children > 1 ) {
6451
+ zend_error_noreturn (E_COMPILE_ERROR ,
6452
+ "Match arms may not share conditions with the default arm" );
6453
+ }
6454
+
6455
+ if (has_default_arm ) {
6456
+ CG (zend_lineno ) = arm_ast -> lineno ;
6457
+ zend_error_noreturn (E_COMPILE_ERROR ,
6458
+ "Match expressions may only contain one default arm" );
6459
+ }
6460
+ has_default_arm = 1 ;
6465
6461
}
6466
- has_default_arm = 1 ;
6467
6462
}
6468
6463
}
6469
6464
@@ -6490,7 +6485,7 @@ static void zend_compile_match(znode *result, zend_ast *ast)
6490
6485
for (uint32_t j = 0 ; j < conds -> children ; j ++ ) {
6491
6486
zend_ast * cond_ast = conds -> child [j ];
6492
6487
6493
- if (do_match_conditions_contain_default ( conds ) ) {
6488
+ if (conds -> child [ 0 ] -> kind == ZEND_AST_DEFAULT ) {
6494
6489
break ;
6495
6490
}
6496
6491
@@ -6547,7 +6542,7 @@ static void zend_compile_match(znode *result, zend_ast *ast)
6547
6542
zend_ast * body_ast = arm_ast -> child [1 ];
6548
6543
zend_ast_list * conds = zend_ast_get_list (arm_ast -> child [0 ]);
6549
6544
6550
- if (! do_match_conditions_contain_default ( conds ) ) {
6545
+ if (conds -> child [ 0 ] -> kind != ZEND_AST_DEFAULT ) {
6551
6546
for (uint32_t j = 0 ; j < conds -> children ; j ++ ) {
6552
6547
zend_ast * cond_ast = conds -> child [j ];
6553
6548
0 commit comments