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

Missing return value from do when calling resume and CATCH is the last statement in a block #2181

Open
hakonhagland opened this issue Aug 5, 2018 · 0 comments

Comments

@hakonhagland
Copy link

The following code prints got value: (Any) whether an exception occurred or not:

use v6;

my $value = do {
    my $result = might-throw();
    CATCH {
        default {
            say "Caught exception: ", .^name;
            .resume;
        }
    }
    #my $result = might-throw(); # <-- It works if I move the call to might-throw()
                                 #     after the CATCH { ... }
};

say "got value: ", $value;

sub might-throw() {
    my $var = <0 1>.pick;
    if $var == 0 {
        die "Zero is not good!";
        -1;
    }
    else {
        1;
    }
}

It could be argued that the presence of the CATCH block should not have an effect on what is considered to be the last statement in the do block and hence what becomes the return value of the do block.

This behavior was confirmed by moving the call to migh-throw() after the CATCH { ... } as indicated with the comment in the code above. In this case the program prints got value: -1 or got value: 1 depending on whether an exception occurred or not, as would be expected for a normal do block.

Environment

  • Operating system: Ubuntu 18.04
  • Compiler version (perl6 -v): Rakudo version 2018.04.1 built on MoarVM version 2018.04.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant