From: Vincent Pit Date: Sun, 15 Feb 2009 11:42:28 +0000 (+0100) Subject: Fix "localize *x, 'y', $cx" to match Perl behaviour X-Git-Tag: v0.07~4 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FScope-Upper.git;a=commitdiff_plain;h=df7ce62096b3b482fc1a0064d6466ddc8907bd66 Fix "localize *x, 'y', $cx" to match Perl behaviour --- diff --git a/Upper.xs b/Upper.xs index 17c4407..2ebee08 100644 --- a/Upper.xs +++ b/Upper.xs @@ -351,11 +351,9 @@ STATIC void su_localize(pTHX_ void *ud_) { if (SvTYPE(sv) >= SVt_PVGV) { gv = (GV *) sv; - if (!val) { /* local *x; */ + if (!val || !SvROK(val)) { /* local *x; or local *x = $val; */ t = SVt_PVGV; - } else if (!SvROK(val)) { /* local *x = $val; */ - goto assign; - } else { /* local *x = \$val; */ + } else { /* local *x = \$val; */ t = SvTYPE(SvRV(val)); deref = 1; } @@ -430,7 +428,6 @@ STATIC void su_localize(pTHX_ void *ud_) { ud, PL_savestack_ix, PL_scopestack[PL_scopestack_ix])); -assign: if (val) SvSetMagicSV((SV *) gv, val); diff --git a/t/20-localize-target.t b/t/20-localize-target.t index 56ebd97..726a588 100644 --- a/t/20-localize-target.t +++ b/t/20-localize-target.t @@ -32,14 +32,17 @@ sub _t { shift->{t} } is $x, undef, 'localize *x, obj => HERE [end]'; } +our $y; + { - local $x = 2; + local $x = 1; + local $y = 2; { - local $x = 3; - localize *x, 1 => HERE; - is $x, undef, 'localize *x, 1 => HERE [ok]'; + local $y = 3; + localize *x, 'y' => HERE; + is $x, 3, "localize *x, 'y' => HERE [ok]"; } - is $x, $] < 5.008009 ? undef : 2, 'localize *x, 1 => HERE [end]'; + is $x, 1, "localize *x, 'y' => HERE [end]"; } undef *x;