From: Gisle Aas Date: Tue, 17 Apr 2001 19:06:45 +0000 (-0700) Subject: foreach defelem magic should only be applied to PL_sv_undef X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8b53063310ef49fb71e3b9e0e66cc606e87c82ff;p=p5sagit%2Fp5-mst-13.2.git foreach defelem magic should only be applied to PL_sv_undef Message-ID: p4raw-id: //depot/perl@9734 --- diff --git a/pp_hot.c b/pp_hot.c index 70c6866..de75f27 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1817,7 +1817,7 @@ PP(pp_iter) SvTEMP_off(sv); else sv = &PL_sv_undef; - if (av != PL_curstack && SvIMMORTAL(sv)) { + if (av != PL_curstack && sv == &PL_sv_undef) { SV *lv = cx->blk_loop.iterlval; if (lv && SvREFCNT(lv) > 1) { SvREFCNT_dec(lv); diff --git a/t/op/misc.t b/t/op/misc.t index 4ff0bf4..125bfe1 100755 --- a/t/op/misc.t +++ b/t/op/misc.t @@ -258,6 +258,15 @@ my @a; $a[2] = 1; for (@a) { $_ = 2 } print "@a\n" EXPECT 2 2 2 ######## +# used to attach defelem magic too all immortal values, +# which made restore of local $_ fail. +foo(2>1); +sub foo { bar() for @_; } +sub bar { local $_; } +print "ok\n"; +EXPECT +ok +######## @a = ($a, $b, $c, $d) = (5, 6); print "ok\n" if ($a[0] == 5 and $a[1] == 6 and !defined $a[2] and !defined $a[3]);