summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerard Goossen <gerard@ggoossen.net>2009-12-27 18:02:37 +0100
committerRafael Garcia-Suarez <rgs@consttype.org>2010-01-10 23:50:36 +0100
commiteac910c876359d864e67b412fa2d9f03b5ba8a0b (patch)
tree096ce89b99906b319e224b554dd62c3b5dd1b0ad
parent885ef6f56b61fd750ef3b1fa614d11480baac635 (diff)
downloadperl-eac910c876359d864e67b412fa2d9f03b5ba8a0b.tar.gz
Retain builtin attributes from pre-declaration. Fixes [perl #68758].
-rw-r--r--op.c3
-rw-r--r--t/op/attrs.t7
-rw-r--r--t/op/sub_lval.t10
3 files changed, 17 insertions, 3 deletions
diff --git a/op.c b/op.c
index db17d142f1..a7205cb9f7 100644
--- a/op.c
+++ b/op.c
@@ -5785,8 +5785,9 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
&& block->op_type != OP_NULL
#endif
) {
+ cv_flags_t existing_builtin_attrs = CvFLAGS(cv) & CVf_BUILTIN_ATTRS;
cv_undef(cv);
- CvFLAGS(cv) = CvFLAGS(PL_compcv);
+ CvFLAGS(cv) = CvFLAGS(PL_compcv) | existing_builtin_attrs;
if (!CvWEAKOUTSIDE(cv))
SvREFCNT_dec(CvOUTSIDE(cv));
CvOUTSIDE(cv) = CvOUTSIDE(PL_compcv);
diff --git a/t/op/attrs.t b/t/op/attrs.t
index 8239572e8a..7c98529617 100644
--- a/t/op/attrs.t
+++ b/t/op/attrs.t
@@ -14,7 +14,7 @@ BEGIN {
use warnings;
-plan 91;
+plan 92;
$SIG{__WARN__} = sub { die @_ };
@@ -114,6 +114,11 @@ eval 'package A; sub PS : lvalue';
@attrs = eval 'attributes::get \&A::PS';
is "@attrs", "lvalue";
+# Test attributes on predeclared subroutines, after definition
+eval 'package A; sub PS : lvalue; sub PS { }';
+@attrs = eval 'attributes::get \&A::PS';
+is "@attrs", "lvalue";
+
# Test ability to modify existing sub's (or XSUB's) attributes.
eval 'package A; sub X { $_[0] } sub X : method';
@attrs = eval 'attributes::get \&A::X';
diff --git a/t/op/sub_lval.t b/t/op/sub_lval.t
index d2e70fe695..c20ffac7be 100644
--- a/t/op/sub_lval.t
+++ b/t/op/sub_lval.t
@@ -3,7 +3,7 @@ BEGIN {
@INC = '../lib';
require './test.pl';
}
-plan tests=>70;
+plan tests=>71;
sub a : lvalue { my $a = 34; ${\(bless \$a)} } # Return a temporary
sub b : lvalue { ${\shift} }
@@ -562,3 +562,11 @@ lvalue attribute ignored after the subroutine has been defined at - line 4.
Can't modify non-lvalue subroutine call in scalar assignment at - line 5, near "3;"
Execution of - aborted due to compilation errors.
====
+
+{
+ my $x;
+ sub lval_decl : lvalue;
+ sub lval_decl { $x }
+ lval_decl = 5;
+ is($x, 5, "subroutine declared with lvalue before definition retains lvalue. [perl #68758]");
+}