diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-05-31 21:32:28 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-05-31 21:32:28 -0700 |
commit | 69b22cd191e9b6eff1e60a75aa38b87646cfb775 (patch) | |
tree | 45a707e25fd637c2f89f7e6d318ab3512755a6c8 /pp_hot.c | |
parent | 6b8305409e650748b2e6fb75634200370b69238b (diff) | |
download | perl-69b22cd191e9b6eff1e60a75aa38b87646cfb775.tar.gz |
Make empty lvalue subs work correctly
In perl 5.8.1 and earlier, sub{} would return @_ in list context. This
was fixed in 5.8.2 for regular subs, but not lvalue subs.
Before the syntactic restriction on return values was removed in
commit 145b2bb, there was a bug affecting compilation of empty subs
before any use statement:
$ perl5.14.0 -e 'sub foo :lvalue {}'
Can't modify stub in lvalue subroutine return at -e line 1, near "{}"
Execution of -e aborted due to compilation errors.
$ perl5.14.0 -le 'use sigtrap; sub foo :lvalue {} print "ok"'
ok
But I digress. :-)
Up to 5.14, lvalue subs were still returning @_, or, rather, the ele-
ments of @_ as separate scalars:
$ perl5.14.0 -Mre -le '(sub :lvalue {}->($a,$b))=(3,4); print "$a $b"'
Useless use of "re" pragma at -e line 0
3 4
(Not exactly useless, eh? The -Mre allows the sub to compile.)
This commit fixes that bug.
Diffstat (limited to 'pp_hot.c')
-rw-r--r-- | pp_hot.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -2745,14 +2745,22 @@ PP(pp_leavesublv) SvREFCNT_inc_void(*mark); } } - else { /* Should not happen? */ + else { + /* sub:lvalue{} will take us here. + Presumably the case of a non-empty array never happens. + */ LEAVE; cxstack_ix--; POPSUB(cx,sv); PL_curpm = newpm; LEAVESUB(sv); - DIE(aTHX_ "%s returned from lvalue subroutine in scalar context", - (MARK > SP ? "Empty array" : "Array")); + DIE(aTHX_ "%s", + (MARK > SP + ? "Can't return undef from lvalue subroutine" + : "Array returned from lvalue subroutine in scalar " + "context" + ) + ); } SP = MARK; } |