develooper Front page | perl.perl5.porters | Postings from January 2014

[perl #2166] foreach spuriously autovivifies

Thread Next
From:
Father Chrysostomos via RT
Date:
January 24, 2014 02:20
Subject:
[perl #2166] foreach spuriously autovivifies
Message ID:
rt-4.0.18-24142-1390529993-1947.2166-15-0@perl.org
On Mon Sep 06 05:57:18 2010, davem wrote:
> I'm marking this ticket as rejected/wontfix, because no-one can agree on
> whether for() should auto-vivify, and if there was agreement, changing
> it would break backwards compatibility.

I have just discovered this ticket, as there is a to-do test for it, which I found when about to add a test for #115194 (a duplicate).

I did not realise this was so controversial.

The problem here is that I broke compatibility (and App::JobLog) when making foreach(pos $x || pos $y) work (by propagating the lvalue context to allow $_ assignment to set pos).  Now foreach($h{k} || $h{l}) vivifies the elements, whereas it did not before.

The obvious solution seemed to be to use defelem magic in foreach, as we already do for sub calls.

Come to think of it, this has already been inconsistent, as constant folding will make for(1||$h{k}) vivify even before my changes.

So I think we need to bite the bullet and decide that this is a bug that needs fixing.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: rejected
https://rt.perl.org/Ticket/Display.html?id=2166

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About