From 522629883726195665ad5ea875afb084d0443961 Mon Sep 17 00:00:00 2001 From: Larry Wall Date: Thu, 13 Mar 2014 13:50:23 -0700 Subject: [PATCH] fix $a.=uniq 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. --- src/core/List.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/List.pm b/src/core/List.pm index eaa48d38505..0032d3abe70 100644 --- a/src/core/List.pm +++ b/src/core/List.pm @@ -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; @@ -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; } @@ -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;