@@ -1913,8 +1913,7 @@ compiler_push_fblock(struct compiler *c, location loc,
1913
1913
{
1914
1914
struct fblockinfo * f ;
1915
1915
if (c -> u -> u_nfblocks >= CO_MAXBLOCKS ) {
1916
- compiler_error (c , loc , "too many statically nested blocks" );
1917
- return ERROR ;
1916
+ return compiler_error (c , loc , "too many statically nested blocks" );
1918
1917
}
1919
1918
f = & c -> u -> u_fblock [c -> u -> u_nfblocks ++ ];
1920
1919
f -> fb_type = t ;
@@ -2102,9 +2101,8 @@ compiler_unwind_fblock_stack(struct compiler *c, location *ploc,
2102
2101
}
2103
2102
struct fblockinfo * top = & c -> u -> u_fblock [c -> u -> u_nfblocks - 1 ];
2104
2103
if (top -> fb_type == EXCEPTION_GROUP_HANDLER ) {
2105
- compiler_error (c , * ploc ,
2104
+ return compiler_error (c , * ploc ,
2106
2105
"'break', 'continue' and 'return' cannot appear in an except* block" );
2107
- return ERROR ;
2108
2106
}
2109
2107
if (loop != NULL && (top -> fb_type == WHILE_LOOP || top -> fb_type == FOR_LOOP )) {
2110
2108
* loop = top ;
@@ -3133,8 +3131,7 @@ compiler_async_for(struct compiler *c, stmt_ty s)
3133
3131
if (IS_TOP_LEVEL_AWAIT (c )){
3134
3132
c -> u -> u_ste -> ste_coroutine = 1 ;
3135
3133
} else if (c -> u -> u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION ) {
3136
- compiler_error (c , loc , "'async for' outside async function" );
3137
- return ERROR ;
3134
+ return compiler_error (c , loc , "'async for' outside async function" );
3138
3135
}
3139
3136
3140
3137
NEW_JUMP_TARGET_LABEL (c , start );
@@ -3212,14 +3209,12 @@ compiler_return(struct compiler *c, stmt_ty s)
3212
3209
int preserve_tos = ((s -> v .Return .value != NULL ) &&
3213
3210
(s -> v .Return .value -> kind != Constant_kind ));
3214
3211
if (c -> u -> u_ste -> ste_type != FunctionBlock ) {
3215
- compiler_error (c , loc , "'return' outside function" );
3216
- return ERROR ;
3212
+ return compiler_error (c , loc , "'return' outside function" );
3217
3213
}
3218
3214
if (s -> v .Return .value != NULL &&
3219
3215
c -> u -> u_ste -> ste_coroutine && c -> u -> u_ste -> ste_generator )
3220
3216
{
3221
- compiler_error (c , loc , "'return' with value in async generator" );
3222
- return ERROR ;
3217
+ return compiler_error (c , loc , "'return' with value in async generator" );
3223
3218
}
3224
3219
3225
3220
if (preserve_tos ) {
@@ -3256,8 +3251,7 @@ compiler_break(struct compiler *c, location loc)
3256
3251
ADDOP (c , loc , NOP );
3257
3252
RETURN_IF_ERROR (compiler_unwind_fblock_stack (c , & loc , 0 , & loop ));
3258
3253
if (loop == NULL ) {
3259
- compiler_error (c , loc , "'break' outside loop" );
3260
- return ERROR ;
3254
+ return compiler_error (c , loc , "'break' outside loop" );
3261
3255
}
3262
3256
RETURN_IF_ERROR (compiler_unwind_fblock (c , & loc , loop , 0 ));
3263
3257
ADDOP_JUMP (c , loc , JUMP , loop -> fb_exit );
@@ -3272,8 +3266,7 @@ compiler_continue(struct compiler *c, location loc)
3272
3266
ADDOP (c , loc , NOP );
3273
3267
RETURN_IF_ERROR (compiler_unwind_fblock_stack (c , & loc , 0 , & loop ));
3274
3268
if (loop == NULL ) {
3275
- compiler_error (c , loc , "'continue' not properly in loop" );
3276
- return ERROR ;
3269
+ return compiler_error (c , loc , "'continue' not properly in loop" );
3277
3270
}
3278
3271
ADDOP_JUMP (c , loc , JUMP , loop -> fb_block );
3279
3272
return SUCCESS ;
@@ -3491,8 +3484,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
3491
3484
s -> v .Try .handlers , i );
3492
3485
location loc = LOC (handler );
3493
3486
if (!handler -> v .ExceptHandler .type && i < n - 1 ) {
3494
- compiler_error (c , loc , "default 'except:' must be last" );
3495
- return ERROR ;
3487
+ return compiler_error (c , loc , "default 'except:' must be last" );
3496
3488
}
3497
3489
NEW_JUMP_TARGET_LABEL (c , next_except );
3498
3490
except = next_except ;
@@ -3931,9 +3923,8 @@ compiler_from_import(struct compiler *c, stmt_ty s)
3931
3923
_PyUnicode_EqualToASCIIString (s -> v .ImportFrom .module , "__future__" ))
3932
3924
{
3933
3925
Py_DECREF (names );
3934
- compiler_error (c , LOC (s ), "from __future__ imports must occur "
3935
- "at the beginning of the file" );
3936
- return ERROR ;
3926
+ return compiler_error (c , LOC (s ), "from __future__ imports must occur "
3927
+ "at the beginning of the file" );
3937
3928
}
3938
3929
ADDOP_LOAD_CONST_NEW (c , LOC (s ), names );
3939
3930
@@ -4425,18 +4416,16 @@ unpack_helper(struct compiler *c, location loc, asdl_expr_seq *elts)
4425
4416
if (elt -> kind == Starred_kind && !seen_star ) {
4426
4417
if ((i >= (1 << 8 )) ||
4427
4418
(n - i - 1 >= (INT_MAX >> 8 ))) {
4428
- compiler_error (c , loc ,
4419
+ return compiler_error (c , loc ,
4429
4420
"too many expressions in "
4430
4421
"star-unpacking assignment" );
4431
- return ERROR ;
4432
4422
}
4433
4423
ADDOP_I (c , loc , UNPACK_EX , (i + ((n - i - 1 ) << 8 )));
4434
4424
seen_star = 1 ;
4435
4425
}
4436
4426
else if (elt -> kind == Starred_kind ) {
4437
- compiler_error (c , loc ,
4427
+ return compiler_error (c , loc ,
4438
4428
"multiple starred expressions in assignment" );
4439
- return ERROR ;
4440
4429
}
4441
4430
}
4442
4431
if (!seen_star ) {
@@ -4884,8 +4873,7 @@ validate_keywords(struct compiler *c, asdl_keyword_seq *keywords)
4884
4873
for (Py_ssize_t j = i + 1 ; j < nkeywords ; j ++ ) {
4885
4874
keyword_ty other = ((keyword_ty )asdl_seq_GET (keywords , j ));
4886
4875
if (other -> arg && !PyUnicode_Compare (key -> arg , other -> arg )) {
4887
- compiler_error (c , LOC (other ), "keyword argument repeated: %U" , key -> arg );
4888
- return ERROR ;
4876
+ return compiler_error (c , LOC (other ), "keyword argument repeated: %U" , key -> arg );
4889
4877
}
4890
4878
}
4891
4879
}
@@ -5614,8 +5602,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)
5614
5602
if (IS_TOP_LEVEL_AWAIT (c )){
5615
5603
c -> u -> u_ste -> ste_coroutine = 1 ;
5616
5604
} else if (c -> u -> u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION ){
5617
- compiler_error (c , loc , "'async with' outside async function" );
5618
- return ERROR ;
5605
+ return compiler_error (c , loc , "'async with' outside async function" );
5619
5606
}
5620
5607
5621
5608
NEW_JUMP_TARGET_LABEL (c , block );
@@ -5812,8 +5799,7 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
5812
5799
return compiler_dictcomp (c , e );
5813
5800
case Yield_kind :
5814
5801
if (c -> u -> u_ste -> ste_type != FunctionBlock ) {
5815
- compiler_error (c , loc , "'yield' outside function" );
5816
- return ERROR ;
5802
+ return compiler_error (c , loc , "'yield' outside function" );
5817
5803
}
5818
5804
if (e -> v .Yield .value ) {
5819
5805
VISIT (c , expr , e -> v .Yield .value );
@@ -5825,12 +5811,10 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
5825
5811
break ;
5826
5812
case YieldFrom_kind :
5827
5813
if (c -> u -> u_ste -> ste_type != FunctionBlock ) {
5828
- compiler_error (c , loc , "'yield' outside function" );
5829
- return ERROR ;
5814
+ return compiler_error (c , loc , "'yield' outside function" );
5830
5815
}
5831
5816
if (c -> u -> u_scope_type == COMPILER_SCOPE_ASYNC_FUNCTION ) {
5832
- compiler_error (c , loc , "'yield from' inside async function" );
5833
- return ERROR ;
5817
+ return compiler_error (c , loc , "'yield from' inside async function" );
5834
5818
}
5835
5819
VISIT (c , expr , e -> v .YieldFrom .value );
5836
5820
ADDOP (c , loc , GET_YIELD_FROM_ITER );
@@ -5840,14 +5824,12 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
5840
5824
case Await_kind :
5841
5825
if (!IS_TOP_LEVEL_AWAIT (c )){
5842
5826
if (c -> u -> u_ste -> ste_type != FunctionBlock ){
5843
- compiler_error (c , loc , "'await' outside function" );
5844
- return ERROR ;
5827
+ return compiler_error (c , loc , "'await' outside function" );
5845
5828
}
5846
5829
5847
5830
if (c -> u -> u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION &&
5848
5831
c -> u -> u_scope_type != COMPILER_SCOPE_COMPREHENSION ) {
5849
- compiler_error (c , loc , "'await' outside async function" );
5850
- return ERROR ;
5832
+ return compiler_error (c , loc , "'await' outside async function" );
5851
5833
}
5852
5834
}
5853
5835
@@ -5894,13 +5876,11 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
5894
5876
case Store :
5895
5877
/* In all legitimate cases, the Starred node was already replaced
5896
5878
* by compiler_list/compiler_tuple. XXX: is that okay? */
5897
- compiler_error (c , loc ,
5879
+ return compiler_error (c , loc ,
5898
5880
"starred assignment target must be in a list or tuple" );
5899
- return ERROR ;
5900
5881
default :
5901
- compiler_error (c , loc ,
5882
+ return compiler_error (c , loc ,
5902
5883
"can't use starred expression here" );
5903
- return ERROR ;
5904
5884
}
5905
5885
break ;
5906
5886
case Slice_kind :
@@ -6142,7 +6122,7 @@ compiler_error(struct compiler *c, location loc,
6142
6122
PyObject * msg = PyUnicode_FromFormatV (format , vargs );
6143
6123
va_end (vargs );
6144
6124
if (msg == NULL ) {
6145
- return 0 ;
6125
+ return ERROR ;
6146
6126
}
6147
6127
PyObject * loc_obj = PyErr_ProgramTextObject (c -> c_filename , loc .lineno );
6148
6128
if (loc_obj == NULL ) {
@@ -6159,7 +6139,7 @@ compiler_error(struct compiler *c, location loc,
6159
6139
exit :
6160
6140
Py_DECREF (loc_obj );
6161
6141
Py_XDECREF (args );
6162
- return 0 ;
6142
+ return ERROR ;
6163
6143
}
6164
6144
6165
6145
/* Emits a SyntaxWarning and returns 1 on success.
@@ -6345,9 +6325,8 @@ emit_and_reset_fail_pop(struct compiler *c, location loc,
6345
6325
static int
6346
6326
compiler_error_duplicate_store (struct compiler * c , location loc , identifier n )
6347
6327
{
6348
- compiler_error (c , loc ,
6328
+ return compiler_error (c , loc ,
6349
6329
"multiple assignments to name %R in pattern" , n );
6350
- return ERROR ;
6351
6330
}
6352
6331
6353
6332
// Duplicate the effect of 3.10's ROT_* instructions using SWAPs.
@@ -6377,8 +6356,7 @@ pattern_helper_store_name(struct compiler *c, location loc,
6377
6356
return ERROR ;
6378
6357
}
6379
6358
if (duplicate ) {
6380
- compiler_error_duplicate_store (c , loc , n );
6381
- return ERROR ;
6359
+ return compiler_error_duplicate_store (c , loc , n );
6382
6360
}
6383
6361
// Rotate this object underneath any items we need to preserve:
6384
6362
Py_ssize_t rotations = pc -> on_top + PyList_GET_SIZE (pc -> stores ) + 1 ;
@@ -6403,18 +6381,16 @@ pattern_unpack_helper(struct compiler *c, location loc,
6403
6381
if (elt -> kind == MatchStar_kind && !seen_star ) {
6404
6382
if ((i >= (1 << 8 )) ||
6405
6383
(n - i - 1 >= (INT_MAX >> 8 ))) {
6406
- compiler_error (c , loc ,
6384
+ return compiler_error (c , loc ,
6407
6385
"too many expressions in "
6408
6386
"star-unpacking sequence pattern" );
6409
- return ERROR ;
6410
6387
}
6411
6388
ADDOP_I (c , loc , UNPACK_EX , (i + ((n - i - 1 ) << 8 )));
6412
6389
seen_star = 1 ;
6413
6390
}
6414
6391
else if (elt -> kind == MatchStar_kind ) {
6415
- compiler_error (c , loc ,
6392
+ return compiler_error (c , loc ,
6416
6393
"multiple starred expressions in sequence pattern" );
6417
- return ERROR ;
6418
6394
}
6419
6395
}
6420
6396
if (!seen_star ) {
@@ -6505,12 +6481,10 @@ compiler_pattern_as(struct compiler *c, pattern_ty p, pattern_context *pc)
6505
6481
if (!pc -> allow_irrefutable ) {
6506
6482
if (p -> v .MatchAs .name ) {
6507
6483
const char * e = "name capture %R makes remaining patterns unreachable" ;
6508
- compiler_error (c , LOC (p ), e , p -> v .MatchAs .name );
6509
- return ERROR ;
6484
+ return compiler_error (c , LOC (p ), e , p -> v .MatchAs .name );
6510
6485
}
6511
6486
const char * e = "wildcard makes remaining patterns unreachable" ;
6512
- compiler_error (c , LOC (p ), e );
6513
- return ERROR ;
6487
+ return compiler_error (c , LOC (p ), e );
6514
6488
}
6515
6489
return pattern_helper_store_name (c , LOC (p ), p -> v .MatchAs .name , pc );
6516
6490
}
@@ -6549,8 +6523,7 @@ validate_kwd_attrs(struct compiler *c, asdl_identifier_seq *attrs, asdl_pattern_
6549
6523
identifier other = ((identifier )asdl_seq_GET (attrs , j ));
6550
6524
if (!PyUnicode_Compare (attr , other )) {
6551
6525
location loc = LOC ((pattern_ty ) asdl_seq_GET (patterns , j ));
6552
- compiler_error (c , loc , "attribute name repeated in class pattern: %U" , attr );
6553
- return ERROR ;
6526
+ return compiler_error (c , loc , "attribute name repeated in class pattern: %U" , attr );
6554
6527
}
6555
6528
}
6556
6529
}
@@ -6571,13 +6544,11 @@ compiler_pattern_class(struct compiler *c, pattern_ty p, pattern_context *pc)
6571
6544
// AST validator shouldn't let this happen, but if it does,
6572
6545
// just fail, don't crash out of the interpreter
6573
6546
const char * e = "kwd_attrs (%d) / kwd_patterns (%d) length mismatch in class pattern" ;
6574
- compiler_error (c , LOC (p ), e , nattrs , nkwd_patterns );
6575
- return ERROR ;
6547
+ return compiler_error (c , LOC (p ), e , nattrs , nkwd_patterns );
6576
6548
}
6577
6549
if (INT_MAX < nargs || INT_MAX < nargs + nattrs - 1 ) {
6578
6550
const char * e = "too many sub-patterns in class pattern %R" ;
6579
- compiler_error (c , LOC (p ), e , p -> v .MatchClass .cls );
6580
- return ERROR ;
6551
+ return compiler_error (c , LOC (p ), e , p -> v .MatchClass .cls );
6581
6552
}
6582
6553
if (nattrs ) {
6583
6554
RETURN_IF_ERROR (validate_kwd_attrs (c , kwd_attrs , kwd_patterns ));
@@ -6636,8 +6607,7 @@ compiler_pattern_mapping(struct compiler *c, pattern_ty p,
6636
6607
// AST validator shouldn't let this happen, but if it does,
6637
6608
// just fail, don't crash out of the interpreter
6638
6609
const char * e = "keys (%d) / patterns (%d) length mismatch in mapping pattern" ;
6639
- compiler_error (c , LOC (p ), e , size , npatterns );
6640
- return ERROR ;
6610
+ return compiler_error (c , LOC (p ), e , size , npatterns );
6641
6611
}
6642
6612
// We have a double-star target if "rest" is set
6643
6613
PyObject * star_target = p -> v .MatchMapping .rest ;
@@ -6659,8 +6629,7 @@ compiler_pattern_mapping(struct compiler *c, pattern_ty p,
6659
6629
RETURN_IF_ERROR (jump_to_fail_pop (c , LOC (p ), pc , POP_JUMP_IF_FALSE ));
6660
6630
}
6661
6631
if (INT_MAX < size - 1 ) {
6662
- compiler_error (c , LOC (p ), "too many sub-patterns in mapping pattern" );
6663
- return ERROR ;
6632
+ return compiler_error (c , LOC (p ), "too many sub-patterns in mapping pattern" );
6664
6633
}
6665
6634
// Collect all of the keys into a tuple for MATCH_KEYS and
6666
6635
// **rest. They can either be dotted names or literals:
@@ -6926,8 +6895,7 @@ compiler_pattern_sequence(struct compiler *c, pattern_ty p,
6926
6895
if (pattern -> kind == MatchStar_kind ) {
6927
6896
if (star >= 0 ) {
6928
6897
const char * e = "multiple starred names in sequence pattern" ;
6929
- compiler_error (c , LOC (p ), e );
6930
- return ERROR ;
6898
+ return compiler_error (c , LOC (p ), e );
6931
6899
}
6932
6900
star_wildcard = WILDCARD_STAR_CHECK (pattern );
6933
6901
only_wildcard &= star_wildcard ;
@@ -6978,8 +6946,7 @@ compiler_pattern_value(struct compiler *c, pattern_ty p, pattern_context *pc)
6978
6946
expr_ty value = p -> v .MatchValue .value ;
6979
6947
if (!MATCH_VALUE_EXPR (value )) {
6980
6948
const char * e = "patterns may only match literals and attribute lookups" ;
6981
- compiler_error (c , LOC (p ), e );
6982
- return ERROR ;
6949
+ return compiler_error (c , LOC (p ), e );
6983
6950
}
6984
6951
VISIT (c , expr , value );
6985
6952
ADDOP_COMPARE (c , LOC (p ), Eq );
@@ -7021,8 +6988,7 @@ compiler_pattern(struct compiler *c, pattern_ty p, pattern_context *pc)
7021
6988
// AST validator shouldn't let this happen, but if it does,
7022
6989
// just fail, don't crash out of the interpreter
7023
6990
const char * e = "invalid match pattern node in AST (kind=%d)" ;
7024
- compiler_error (c , LOC (p ), e , p -> kind );
7025
- return ERROR ;
6991
+ return compiler_error (c , LOC (p ), e , p -> kind );
7026
6992
}
7027
6993
7028
6994
static int
0 commit comments