diff options
-rw-r--r-- | op.c | 3 | ||||
-rw-r--r-- | t/op/hash.t | 18 |
2 files changed, 19 insertions, 2 deletions
@@ -9661,7 +9661,8 @@ Perl_rpeep(pTHX_ register OP *o) /* Make the CONST have a shared SV */ svp = cSVOPx_svp(((BINOP*)o)->op_last); - if (!SvFAKE(sv = *svp) || !SvREADONLY(sv)) { + if ((!SvFAKE(sv = *svp) || !SvREADONLY(sv)) + && SvTYPE(sv) < SVt_PVMG && !SvROK(sv)) { key = SvPV_const(sv, keylen); lexname = newSVpvn_share(key, SvUTF8(sv) ? -(I32)keylen : (I32)keylen, diff --git a/t/op/hash.t b/t/op/hash.t index d75d059f3d..fe8a856f19 100644 --- a/t/op/hash.t +++ b/t/op/hash.t @@ -8,7 +8,7 @@ BEGIN { use strict; -plan tests => 7; +plan tests => 8; my %h; @@ -130,3 +130,19 @@ $destroyed = 0; $h{key} = bless({}, 'Class'); } is($destroyed, 1, 'Timely hash destruction with lvalue keys'); + + +# [perl #79178] Hash keys must not be stringified during compilation +# Run perl -MO=Concise -e '$a{\"foo"}' on a non-threaded pre-5.13.8 version +# to see why. +{ + my $key; + package bar; + sub TIEHASH { bless {}, $_[0] } + sub FETCH { $key = $_[1] } + package main; + tie my %h, "bar"; + $h{\'foo'}; + is ref $key, SCALAR => + 'hash keys are not stringified during compilation'; +} |