Skip to content

Instantly share code, notes, and snippets.

@usev6
Created November 28, 2015 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usev6/cc463b2166e1107f06bd to your computer and use it in GitHub Desktop.
Save usev6/cc463b2166e1107f06bd to your computer and use it in GitHub Desktop.
Avoid NullPointerException executing 'my %h; say %h'
diff --git a/src/core/Mu.pm b/src/core/Mu.pm
index f123489..896630e 100644
--- a/src/core/Mu.pm
+++ b/src/core/Mu.pm
@@ -342,7 +342,7 @@ Please refactor this code using the new Iterator / Seq interface.
method gistseen(Mu:D \SELF: $id, $gist, *%named) {
if $*gistseen -> \sems {
my str $WHICH = nqp::unbox_s(self.WHICH);
- if nqp::atkey(sems,$WHICH) {
+ if sems<$WHICH> {
nqp::bindkey(sems,$WHICH,2);
"{$id}_{nqp::objectid(SELF)}";
}
@@ -369,7 +369,7 @@ Please refactor this code using the new Iterator / Seq interface.
method perlseen(Mu:D \SELF: $id, $perl, *%named) {
if $*perlseen -> \sems {
my str $WHICH = nqp::unbox_s(self.WHICH);
- if nqp::atkey(sems,$WHICH) {
+ if sems<$WHICH> {
nqp::bindkey(sems,$WHICH,2);
"{$id}_{nqp::objectid(SELF)}";
}
@usev6
Copy link
Author

usev6 commented Nov 28, 2015

diff --git a/src/core/Mu.pm b/src/core/Mu.pm
index f123489..9317a1c 100644
--- a/src/core/Mu.pm
+++ b/src/core/Mu.pm
@@ -342,7 +342,7 @@ Please refactor this code using the new Iterator / Seq interface.
     method gistseen(Mu:D \SELF: $id, $gist, *%named) {
         if $*gistseen -> \sems {
             my str $WHICH = nqp::unbox_s(self.WHICH);
-            if nqp::atkey(sems,$WHICH) {
+            if nqp::existskey(sems,$WHICH) && nqp::atkey(sems,$WHICH) {
                 nqp::bindkey(sems,$WHICH,2);
                 "{$id}_{nqp::objectid(SELF)}";
             }
@@ -369,7 +369,7 @@ Please refactor this code using the new Iterator / Seq interface.
     method perlseen(Mu:D \SELF: $id, $perl, *%named) {
         if $*perlseen -> \sems {
             my str $WHICH = nqp::unbox_s(self.WHICH);
-            if nqp::atkey(sems,$WHICH) {
+            if nqp::existskey(sems,$WHICH) && nqp::atkey(sems,$WHICH) {
                 nqp::bindkey(sems,$WHICH,2);
                 "{$id}_{nqp::objectid(SELF)}";
             }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment