Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #147 from lizmat/existstypedhash
Fix for "exists" handling on typed hashes
  • Loading branch information
lizmat committed Jun 2, 2013
2 parents 7d5480e + 6973abb commit 99c82d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/core/EnumMap.pm
Expand Up @@ -75,11 +75,11 @@ my class EnumMap does Associative {
}
}

method at_key($key is copy) is rw {
$key = $key.Str;
self.exists($key)
?? nqp::atkey($!storage, nqp::unbox_s($key))
!! Any
method at_key($key) is rw {
my str $skey = nqp::unbox_s($key.Str);
nqp::defined($!storage) && nqp::existskey($!storage, $skey)
?? nqp::atkey($!storage, $skey)
!! Any
}

method STORE_AT_KEY(\key, Mu \value) is rw {
Expand Down
7 changes: 6 additions & 1 deletion src/core/Hash.pm
Expand Up @@ -137,7 +137,7 @@ my class Hash {
has $!keys;
method at_key(::?CLASS:D: TKey \key, TValue $v? is copy) is rw {
my $key_which = key.WHICH;
self.exists($key_which)
self.exists(key)
?? nqp::findmethod(EnumMap, 'at_key')(self, $key_which)
!! pir::setattribute__0PPsP($v, Scalar, '$!whence',
-> {
Expand Down Expand Up @@ -185,6 +185,11 @@ my class Hash {
nqp::unbox_s($key_which),
bindval)
}
method exists(TKey \key) {
nqp::defined($!keys)
?? nqp::p6bool(nqp::existskey($!keys, nqp::unbox_s(key.WHICH)))
!! False
}
method pairs() {
return unless nqp::defined(nqp::getattr(self, EnumMap, '$!storage'));
gather {
Expand Down

0 comments on commit 99c82d3

Please sign in to comment.