Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix for "exists" handling on typed hashes
Made in cooperation with jnthn++ and moritz++
  • Loading branch information
lizmat committed May 19, 2013
1 parent 2a04f23 commit 88dae22
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(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(::?CLASS:D: Mu \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 88dae22

Please sign in to comment.