summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--op.c3
-rw-r--r--t/op/hash.t18
2 files changed, 19 insertions, 2 deletions
diff --git a/op.c b/op.c
index 53641c7a8d..4c3c876662 100644
--- a/op.c
+++ b/op.c
@@ -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';
+}