Skip to content
Browse files

Merge pull request #147 from lizmat/existstypedhash

Fix for "exists" handling on typed hashes
  • Loading branch information...
2 parents 7d5480e + 6973abb commit 99c82d37321198d296cea321b8877deb52f13a23 @lizmat lizmat committed Jun 2, 2013
Showing with 11 additions and 6 deletions.
  1. +5 −5 src/core/EnumMap.pm
  2. +6 −1 src/core/Hash.pm
View
10 src/core/EnumMap.pm
@@ -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 {
View
7 src/core/Hash.pm
@@ -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',
-> {
@@ -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 {

0 comments on commit 99c82d3

Please sign in to comment.
Something went wrong with that request. Please try again.