Skip to content

Commit

Permalink
fix $a.=uniq
Browse files Browse the repository at this point in the history
The referent of $a is getting clobbered before uniq can get any values
from it.  Wrapping the list in gather/take gives us enough indirection
that we can return a new $a without clobbering the old value.
  • Loading branch information
TimToady committed Mar 13, 2014
1 parent eebf846 commit 5226298
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/core/List.pm
Expand Up @@ -404,25 +404,25 @@ my class List does Positional { # declared in BOOTSTRAP
multi method uniq() {
my $seen := nqp::hash();
my str $target;
map {
gather map {
$target = nqp::unbox_s($_.WHICH);
if nqp::existskey($seen, $target) {
next;
}
else {
nqp::bindkey($seen, $target, 1);
$_;
.take;
}
}, @.list;
}
multi method uniq( :&as!, :&with! ) {
my @seen; # should be Mu, but doesn't work in settings :-(
my Mu $target;
map {
gather map {
$target = &as($_);
if first( { with($target,$_) }, @seen ) =:= Nil {
@seen.push($target);
$_;
.take;
}
else {
next;
Expand All @@ -432,14 +432,14 @@ my class List does Positional { # declared in BOOTSTRAP
multi method uniq( :&as! ) {
my $seen := nqp::hash();
my str $target;
map {
gather map {
$target = &as($_).WHICH;
if nqp::existskey($seen, $target) {
next;
}
else {
nqp::bindkey($seen, $target, 1);
$_;
.take;
}
}, @.list;
}
Expand All @@ -448,11 +448,11 @@ my class List does Positional { # declared in BOOTSTRAP

my @seen; # should be Mu, but doesn't work in settings :-(
my Mu $target;
map {
gather map {
$target := $_;
if first( { with($target,$_) }, @seen ) =:= Nil {
@seen.push($target);
$_;
.take;
}
else {
next;
Expand Down

0 comments on commit 5226298

Please sign in to comment.