Skip to content

Commit

Permalink
Fix a bug with gist over Junction keys
Browse files Browse the repository at this point in the history
Autothreading over `Junction` caused a throw in `Rakudo::Sorting`
`MERGESORT-REIFIED-LIST-AS` method. Since this only happens with
parameterized hashes, the fix is done via adding `:safe` named to
`Hash::Object` sort method.
  • Loading branch information
vrurg committed Feb 9, 2022
1 parent fa1f4a7 commit df09bef
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/core.c/Hash/Object.pm6
Expand Up @@ -135,15 +135,17 @@ my role Hash::Object[::TValue, ::TKey] does Associative[TValue] {
!! Nil
}

multi method sort(::?CLASS:D: --> Seq:D) {
multi method sort(::?CLASS:D: Bool :$safe --> Seq:D) {
# With :safe we don't sort directly over the keys but stringify them appropriately first. This is necessary
# whenever a key could happen to be a Junction, in which case MERGESORT-REIFIED-LIST-AS would throw due to
# autothreading.
Seq.new(
Rakudo::Iterator.ReifiedList(
Rakudo::Sorting.MERGESORT-REIFIED-LIST-AS(
self.IterationBuffer.List,
*.key
)
)
)
($safe
?? { ($_ ~~ Junction ?? .gist !! .Stringy) with .key }
!! *.key))))
}

my class Keys does Rakudo::Iterator::Mappy {
Expand Down Expand Up @@ -263,6 +265,15 @@ my role Hash::Object[::TValue, ::TKey] does Associative[TValue] {
})
}

multi method gist(::?CLASS:D:) {
self.gistseen: self.^name, {
'{'
~ self.sort(:safe).head(100).map(*.gist).join(', ')
~ (', ...' if self.elems > 100)
~ '}'
}
}

# gotta force capture keys to strings or binder fails
method Capture() {
nqp::elems(nqp::getattr(self,Map,'$!storage'))
Expand Down

0 comments on commit df09bef

Please sign in to comment.