summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--op.c4
-rw-r--r--t/lib/warnings/op7
2 files changed, 10 insertions, 1 deletions
diff --git a/op.c b/op.c
index 2be77d063f..d807c6f8b2 100644
--- a/op.c
+++ b/op.c
@@ -10661,7 +10661,9 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs,
if (ckWARN(WARN_REDEFINE)
|| ( ckWARN_d(WARN_REDEFINE)
&& ( !const_sv || SvRV(gv) == const_sv
- || sv_cmp(SvRV(gv), const_sv) ))) {
+ || SvTYPE(const_sv) == SVt_PVAV
+ || SvTYPE(SvRV(gv)) == SVt_PVAV
+ || sv_cmp(SvRV(gv), const_sv) ))) {
assert(cSVOPo);
Perl_warner(aTHX_ packWARN(WARN_REDEFINE),
"Constant subroutine %" SVf " redefined",
diff --git a/t/lib/warnings/op b/t/lib/warnings/op
index 03f8c3c33c..4ef9d565f1 100644
--- a/t/lib/warnings/op
+++ b/t/lib/warnings/op
@@ -1025,6 +1025,13 @@ EXPECT
OPTIONS regex
Constant subroutine main::fred redefined at .*lib/constant\.pm line \d+
########
+# op.c related to github #20742
+# produced an assertion failure
+use constant x => 1, 2;
+sub x () { 1 }
+EXPECT
+Constant subroutine x redefined at - line 4.
+########
# op.c
use feature "lexical_subs", "state";
my sub fred () { 1 }