Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add a typed exception
for accessing stuff through CALLER that is not dynamic
  • Loading branch information
moritz committed Aug 11, 2013
1 parent 42a37a0 commit 2566e75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -1281,6 +1281,13 @@ my class X::Multi::NoMatch is Exception {
}
}

my class X::Caller::NotDynamic is Exception {
has $.symbol;
method message() {
"Cannot access '$.symbol' through CALLER, because it is not declared as dynamic";
}
}

{
my %c_ex;
%c_ex{'X::TypeCheck::Binding'} := sub ($got, $expected) is hidden_from_backtrace {
Expand Down
5 changes: 4 additions & 1 deletion src/core/PseudoStash.pm
@@ -1,4 +1,5 @@
my class X::Bind { ... }
my class X::Caller::NotDynamic { ... }

my class PseudoStash is EnumMap {
has Mu $!ctx;
Expand Down Expand Up @@ -119,7 +120,9 @@ my class PseudoStash is EnumMap {
if !$res.VAR.dynamic
&& nqp::substr($nkey, 1, 1) ne '*'
&& $key ne '$_' && $key ne '$/' && $key ne '$!' {
die "You're trying to access $key through CALLER, but it is not dynamic."
X::Caller::NotDynamic.new(
symbol => $key,
).throw;
}
}
$res;
Expand Down

0 comments on commit 2566e75

Please sign in to comment.