Skip to content
Permalink
Browse files

Add null/defined checks for %!hash

The first check avoids a NullPointerException in S06-other/main-refactored.t
on the JVM backend. The failing code was:

  sub MAIN("NEVER MATCHES") { 42 }
  • Loading branch information...
usev6 committed Mar 30, 2019
1 parent a5b2238 commit f26fbd374a28f5a0a3117f1b58507dcb026ff332
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/core/Capture.pm6
@@ -34,10 +34,18 @@ my class Capture { # declared in BOOTSTRAP
}

multi method AT-KEY(Capture:D: Str:D \key) is raw {
nqp::ifnull(nqp::atkey(%!hash,nqp::unbox_s(key)), Nil)
nqp::if(
(nqp::isnull(%!hash) || !nqp::defined(%!hash)),
Nil,
nqp::ifnull(nqp::atkey(%!hash,nqp::unbox_s(key)), Nil)
)
}
multi method AT-KEY(Capture:D: \key) is raw {
nqp::ifnull(nqp::atkey(%!hash,nqp::unbox_s(key.Str)), Nil)
nqp::if(
(nqp::isnull(%!hash) || !nqp::defined(%!hash)),
Nil,
nqp::ifnull(nqp::atkey(%!hash,nqp::unbox_s(key.Str)), Nil)
)
}

multi method AT-POS(Capture:D: int \pos) is raw {

0 comments on commit f26fbd3

Please sign in to comment.
You can’t perform that action at this time.