Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEAVE block skipped when die is called #3148

Closed
p6rt opened this issue Oct 26, 2015 · 4 comments
Closed

LEAVE block skipped when die is called #3148

p6rt opened this issue Oct 26, 2015 · 4 comments
Labels

Comments

@p6rt
Copy link

@p6rt p6rt commented Oct 26, 2015

Migrated from rt.perl.org#126459 (status was 'new')

Searchable as RT126459$

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 26, 2015

From @gfldex

sub f(){
  ENTER { note '1) f has been entered' }
  LEAVE { note '2) f has been left' }
  say '3) here be dragons';
  die '4) that happend to be deadly';
}

f();
say '5) am I alive?';

CATCH {
  when X​::AdHoc { note q{6) no, I'm dead}; exit 1 }
}

# OUTPUT​:
# 1) f has been entered
# 3) here be dragons
# 6) no, I'm dead

# When die is replaced with fail, the LEAVE block is called. This is
# neither specced nor documented. So it's either a bug or some mission
# documentation.

@p6rt
Copy link
Author

@p6rt p6rt commented Oct 26, 2015

From @gfldex

Removing 'exit 1' get's the LEAVE block called. In my eyes the LEAVE block
should be called in that case too, because it may contain cleanup code and
the CATCH may be in a different compunit, what will cause subtile bugs
that are hard to test.

@JJ
Copy link
Contributor

@JJ JJ commented Jan 7, 2020

This should probably better be clarified in documentation, as @gfldex says

@JJ JJ transferred this issue from Raku/old-issue-tracker Jan 7, 2020
@lizmat
Copy link
Collaborator

@lizmat lizmat commented Jan 7, 2020

This has nothing to do with CATCH: the issue can be golfed to:

sub a() { LEAVE say "left"; exit 1 };
a

I guess because technically the exit is a sub that is being called, that does the exiting magic, like calling all END blocks, but it never returns, thus never leaving the block in which it was called, and thus never calling the LEAVE phaser.

sub a() { END say "ended"; exit 1 };
a   # ended

I don't think we're going to have an easy solution to that. So yes, I think this is a trap that needs documenting.

@JJ JJ added the trap label Feb 8, 2020
@JJ JJ closed this as completed in 6de783d Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants