Skip to content
Permalink
Browse files

Map.WHICH only value type if all its elements are

As soon as a value is encountered that is not a ValueObjAt, revert to
Mu::WHICH.  Fixed R#2447
  • Loading branch information...
lizmat committed Oct 30, 2018
1 parent 1c1527f commit 4e0a1c243210fcb280b9606d68f79ca330b13e8f
Showing with 14 additions and 9 deletions.
  1. +14 −9 src/core/Map.pm6
@@ -16,25 +16,30 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
nqp::join(
'|',
nqp::stmts( # cannot use native str arrays early in setting
(my $keys := nqp::list_s),
(my \keys := nqp::list_s),
(my \iter := nqp::iterator($!storage)),
nqp::while(
iter,
nqp::push_s($keys,nqp::iterkey_s(nqp::shift(iter)))
nqp::push_s(keys,nqp::iterkey_s(nqp::shift(iter)))
),
(my $sorted := Rakudo::Sorting.MERGESORT-str($keys)),
(my \sorted := Rakudo::Sorting.MERGESORT-str(keys)),
(my int $i = -1),
(my int $elems = nqp::elems($sorted)),
(my $strings := nqp::list_s),
(my int $elems = nqp::elems(sorted)),
(my \strings := nqp::list_s),
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),$elems),
nqp::stmts(
(my $key := nqp::atpos_s($sorted,$i)),
nqp::push_s($strings,$key),
nqp::push_s($strings,nqp::atkey($!storage,$key).perl)
(my \key := nqp::atpos_s(sorted,$i)),
nqp::push_s(strings,key),
(my \value := nqp::atkey($!storage,key).WHICH),
nqp::if(
nqp::istype(value,ValueObjAt),
nqp::push_s(strings,value),
(return self.Mu::WHICH)
)
)
),
$strings
strings
)
)
)

0 comments on commit 4e0a1c2

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