I don’t think that’s a bug, that’s just the scope rules of the language. Some languages create a new scope for foreach loops (like Perl) so that variables in a greater surrounding scope with the same variable name do not leak inside:
sh-3.2$ perl -e 'my @a=("a","b","c"); my $a; foreach $a(@a) { print $a . " ";} print "\nAfter: $a\n";'
a b c
After:
And the same workaround:
sh-3.2$ perl -e 'my @a=("a","b","c"); my $b; foreach $a(@a) { print $a . " "; $b = $a;} print "\nAfter: $b\n";'
a b c
After: c
Others, like Ruby, don’t:
sh-3.2$ ruby
x = String.new
['a','b','c'].each{|x| print "#{x} "}
puts "\nAfter: #{x}"
a b c
After: c
More importantly, this scope handling hasn’t changed in 4rc1, here’s the same test on 3.30: