File tree Expand file tree Collapse file tree 4 files changed +77
-3
lines changed Expand file tree Collapse file tree 4 files changed +77
-3
lines changed Original file line number Diff line number Diff line change @@ -368,7 +368,19 @@ manager will later use a regex to expand these into links.
368
368
369
369
=item *
370
370
371
- XXX
371
+ Exceptions thrown and caught entirely within a C<defer {}> or C<finally {}>
372
+ block no longer stop the outer run-loop.
373
+
374
+ Code such as the following would stop running the contents of the C<defer>
375
+ block once the inner exception in the inner C<try>/C<catch> block was caught.
376
+ This has now been fixed, and runs as expected. ([GH #23064]).
377
+
378
+ defer {
379
+ try { die "It breaks\n"; }
380
+ catch ($e) { warn $e }
381
+
382
+ say "This line would never run";
383
+ }
372
384
373
385
=back
374
386
Original file line number Diff line number Diff line change @@ -6475,9 +6475,37 @@ _invoke_defer_block(pTHX_ U8 type, void *_arg)
6475
6475
SAVETMPS ;
6476
6476
6477
6477
SAVEOP ();
6478
+ OP * was_PL_op = PL_op ;
6478
6479
PL_op = start ;
6479
6480
6480
- CALLRUNOPS (aTHX );
6481
+ dJMPENV ;
6482
+ int ret ;
6483
+ JMPENV_PUSH (ret );
6484
+ switch (ret ) {
6485
+ case 0 : /* normal start */
6486
+ redo_body :
6487
+ CALLRUNOPS (aTHX );
6488
+ break ;
6489
+
6490
+ case 3 : /* exception happened */
6491
+ if (PL_restartjmpenv == PL_top_env ) {
6492
+ if (!PL_restartop )
6493
+ break ;
6494
+ PL_restartjmpenv = NULL ;
6495
+ PL_op = PL_restartop ;
6496
+ PL_restartop = NULL ;
6497
+ goto redo_body ;
6498
+ }
6499
+
6500
+ /* FALLTHROUGH */
6501
+ default :
6502
+ JMPENV_POP ;
6503
+ PL_op = was_PL_op ;
6504
+ JMPENV_JUMP (ret );
6505
+ NOT_REACHED ;
6506
+ }
6507
+
6508
+ JMPENV_POP ;
6481
6509
6482
6510
FREETMPS ;
6483
6511
LEAVE ;
Original file line number Diff line number Diff line change 6
6
set_up_inc(' ../lib' );
7
7
}
8
8
9
- plan 28 ;
9
+ plan 29 ;
10
10
11
11
use feature ' defer' ;
12
12
no warnings ' experimental::defer' ;
@@ -285,3 +285,18 @@ no warnings 'experimental::defer';
285
285
like($e , qr / ^Bareword "foo" not allowed while "strict subs" in use at / ,
286
286
' Error from finalization' );
287
287
}
288
+
289
+ # GH#23604
290
+ {
291
+ my $ok ;
292
+ {
293
+ defer {
294
+ eval { die " Ignore this error\n " };
295
+ $ok .= " k" ;
296
+ }
297
+
298
+ $ok .= " o" ;
299
+ }
300
+
301
+ is($ok , " ok" , ' eval{die} inside defer does not stop runloop' );
302
+ }
Original file line number Diff line number Diff line change @@ -330,6 +330,25 @@ no warnings 'experimental::try';
330
330
ok($finally_invoked , ' finally block still invoked for side-effects' );
331
331
}
332
332
333
+ # Variant of GH#23604
334
+ {
335
+ my $ok ;
336
+ try {
337
+ # nothing
338
+ }
339
+ catch ($e ) {}
340
+ finally {
341
+ try {
342
+ die " Ignore this error\n "
343
+ }
344
+ catch ($e ) {}
345
+
346
+ $ok = " ok" ;
347
+ }
348
+
349
+ is($ok , " ok" , ' try{die} inside try/finally does not stop runloop' );
350
+ }
351
+
333
352
# Nicer compiletime errors
334
353
{
335
354
my $e ;
You can’t perform that action at this time.
0 commit comments