Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 284f609

Browse files
committed
:const init - honor more attribs
with constant folded assignments. otherwise just the folded op would be returned, and the remaining run-time attrs ignored.
1 parent 010ef5b commit 284f609

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

op.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4687,6 +4687,7 @@ Perl_newASSIGNOP_maybe_const(pTHX_ OP *left, I32 optype, OP *right)
46874687
((num = attrs_has_const(left, TRUE)) != 0) ))
46884688
{ /* my $x :const = $y; dissect my_attrs() */
46894689
OP *attr = OpSIBLING(OpFIRST(left));
4690+
OP *assign = NULL;
46904691
/* defer :const after = */
46914692
if (OP_TYPE_ISNT(attr, OP_ENTERSUB)) {
46924693
left = attr;
@@ -4709,15 +4710,15 @@ Perl_newASSIGNOP_maybe_const(pTHX_ OP *left, I32 optype, OP *right)
47094710
left->op_private = 0; /* rm LVINTRO */
47104711
SvREADONLY_on(lsv);
47114712
op_free(right);
4712-
return ck_pad(left);
4713+
assign = ck_pad(left);
47134714
} else if (SvTYPE(lsv) == SVt_PVAV) {
47144715
DEBUG_k(Perl_deb(aTHX_ "my %s[1] :const = (%s)\n",
47154716
PAD_COMPNAME_PV(left->op_targ), SvPEEK(rsv)));
47164717
AvSHAPED_on((AV*)lsv); /* XXX we can even type it */
47174718
av_store((AV*)lsv,0,SvREFCNT_inc_NN(rsv));
47184719
SvREADONLY_on(lsv);
47194720
op_free(right);
4720-
return ck_pad(left);
4721+
assign = ck_pad(left);
47214722
}
47224723
}
47234724
/* hashes not yet.
@@ -4745,7 +4746,7 @@ Perl_newASSIGNOP_maybe_const(pTHX_ OP *left, I32 optype, OP *right)
47454746
AvSHAPED_on(lsv); /* check if to set type */
47464747
SvREADONLY_on(lsv);
47474748
op_free(right);
4748-
return ck_pad(left);
4749+
assign = ck_pad(left);
47494750
}
47504751
} else { /* range */
47514752
o = OpFIRST(OpFIRST(right));
@@ -4770,7 +4771,7 @@ Perl_newASSIGNOP_maybe_const(pTHX_ OP *left, I32 optype, OP *right)
47704771
AvSHAPED_on(lsv);
47714772
SvREADONLY_on(lsv);
47724773
op_free(right);
4773-
return ck_pad(left);
4774+
assign = ck_pad(left);
47744775
}
47754776
}
47764777
}
@@ -4788,7 +4789,7 @@ Perl_newASSIGNOP_maybe_const(pTHX_ OP *left, I32 optype, OP *right)
47884789
SvPEEK(lsv), SvPEEK(rsv)));
47894790
SvSetMagicSV(lsv, SvREFCNT_inc_NN(rsv));
47904791
SvREADONLY_on(lsv);
4791-
return ck_rvconst(left);
4792+
assign = ck_rvconst(left);
47924793
}
47934794
} else if (IS_TYPE(left, RV2AV)) {
47944795
GV* gv = cGVOPx_gv(OpFIRST(left));
@@ -4802,7 +4803,7 @@ Perl_newASSIGNOP_maybe_const(pTHX_ OP *left, I32 optype, OP *right)
48024803
av_store(lsv, 0, SvREFCNT_inc_NN(rsv));
48034804
SvREADONLY_on(lsv);
48044805
op_free(right);
4805-
return ck_rvconst(left);
4806+
assign = ck_rvconst(left);
48064807
} else if (IS_TYPE(right, LIST)) {
48074808
SSize_t i;
48084809
OP *o = OpSIBLING(OpFIRST(right));
@@ -4817,21 +4818,25 @@ Perl_newASSIGNOP_maybe_const(pTHX_ OP *left, I32 optype, OP *right)
48174818
AvSHAPED_on(lsv); /* we can even type it */
48184819
SvREADONLY_on(lsv);
48194820
op_free(right);
4820-
return ck_rvconst(left);
4821+
assign = ck_rvconst(left);
48214822
}
48224823
}
48234824
}
48244825
/* else not constant foldable. like a lhs ref, hash or list. */
48254826
/* if :const is the only attr skip attributes->import */
48264827
if (num > 1) {
48274828
return op_append_list(OP_LINESEQ,
4828-
newASSIGNOP(OPf_STACKED|OPf_SPECIAL,
4829-
left, optype, right),
4829+
assign
4830+
? assign
4831+
: newASSIGNOP(OPf_STACKED|OPf_SPECIAL,
4832+
left, optype, right),
48304833
scalar(attr));
48314834
} else {
48324835
op_free(attr);
4833-
return newASSIGNOP(OPf_STACKED|OPf_SPECIAL,
4834-
left, optype, right);
4836+
return assign
4837+
? assign
4838+
: newASSIGNOP(OPf_STACKED|OPf_SPECIAL,
4839+
left, optype, right);
48354840
}
48364841
}
48374842
/* no else as gcc-6 is not clever enough and emits a wrong warning */

0 commit comments

Comments
 (0)