diff --git a/sv.c b/sv.c index 4e15c6236219..6bf92f9d1a71 100644 --- a/sv.c +++ b/sv.c @@ -10126,7 +10126,10 @@ Perl_sv_resetpvn(pTHX_ const char *s, STRLEN len, HV * const stash) sv = GvSV(gv); if (sv && !SvREADONLY(sv)) { SV_CHECK_THINKFIRST_COW_DROP(sv); - if (!isGV(sv)) SvOK_off(sv); + if (!isGV(sv)) { + SvOK_off(sv); + SvSETMAGIC(sv); + } } if (GvAV(gv)) { av_clear(GvAV(gv)); diff --git a/t/op/reset.t b/t/op/reset.t index bb5fbfce5ee5..e4dcfc77f35b 100644 --- a/t/op/reset.t +++ b/t/op/reset.t @@ -7,7 +7,7 @@ BEGIN { } use strict; -plan tests => 40; +plan tests => 45; package aiieee; @@ -190,6 +190,30 @@ SKIP: } } +# magic reset #20763 +{ + { + local $^W = 1; # we're resetting this + my $warn = ''; + local $SIG{__WARN__} = sub { $warn .= "@_\n" }; + reset "\cW"; + like($warn, qr/uninitialized/, "magic tries to SvIV() the new value"); + $warn = ''; + is($^W, 0, q"check $^W has been zeroed"); + is($warn, '', "should be no more warnings"); + } + { + local $| = 1; + no warnings 'uninitialized'; + reset '|'; + is($|, 0, q"check magic applied to $|"); + } + + eval { reset "1" }; + like($@, qr/Modification of a read-only value attempted/, + "\$1 isn't marked read-only, but throws on set magic"); +} + __DATA__ #!perl use warnings;