diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-10-24 10:53:46 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-10-24 10:54:27 -0700 |
commit | 32cbae3f95283fbf92f1e0d0d188dbb5d5ad5804 (patch) | |
tree | 66bec29e7de1e1166d2e42bdc018e2bfae5b4fcf /op.c | |
parent | a373464fd655c7246cf689f421efc503307b705c (diff) | |
download | perl-32cbae3f95283fbf92f1e0d0d188dbb5d5ad5804.tar.gz |
Restore prev. behaviour of @a||... in lv sub
$ perl5.18.1 -lwe 'my @a; sub i:lvalue {@a||@b} @a=1; (i())=3'
Name "main::b" used only once: possible typo at -e line 1.
Useless assignment to a temporary at -e line 1.
Bleadperl:
$ ./perl -Ilib -lwe 'my @a; sub i:lvalue {@a||@b} @a=1; (i())=3'
Name "main::b" used only once: possible typo at -e line 1.
Can't return array to lvalue scalar context at -e line 1.
I accidentally changed it in commit 2ec7f6f242 by propagating the
lvalue context. This commit changes it back by only flagging the
rv2av op as being in an lvalue sub if it is not already flagged as
being in scalar context.
The old behaviour was inconsistent, and this commit does restore it
(see the tests), but resolving that discrepancy is for a future commit
(if I ever get to it).
In any case, ‘Can't return array to lvalue scalar context’ is wrong.
Diffstat (limited to 'op.c')
-rw-r--r-- | op.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -2164,7 +2164,11 @@ Perl_op_lvalue_flags(pTHX_ OP *o, I32 type, U32 flags) localize = 1; /* FALL THROUGH */ case OP_AASSIGN: - if (type == OP_LEAVESUBLV) + /* Do not apply the lvsub flag for rv2[ah]v in scalar context. */ + if (type == OP_LEAVESUBLV && ( + (o->op_type != OP_RV2AV && o->op_type != OP_RV2HV) + || (o->op_flags & OPf_WANT) != OPf_WANT_SCALAR + )) o->op_private |= OPpMAYBE_LVSUB; /* FALL THROUGH */ case OP_NEXTSTATE: @@ -2208,7 +2212,8 @@ Perl_op_lvalue_flags(pTHX_ OP *o, I32 type, U32 flags) return o; /* Treat \(@foo) like ordinary list. */ if (scalar_mod_type(o, type)) goto nomod; - if (type == OP_LEAVESUBLV) + if ((o->op_flags & OPf_WANT) != OPf_WANT_SCALAR + && type == OP_LEAVESUBLV) o->op_private |= OPpMAYBE_LVSUB; /* FALL THROUGH */ case OP_PADSV: |