summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDagfinn Ilmari Mannsåker <ilmari@ilmari.org>2015-12-21 19:25:32 +0000
committerRicardo Signes <rjbs@cpan.org>2016-01-16 21:45:16 -0500
commite1ccd2206d2572b12ff2ad8efe6b1370c580898f (patch)
tree9bf4f131bd3487cf4e91e856501816df1bdd6567
parentcda27dcf504146747d450c00da849d80744fdf7d (diff)
downloadperl-e1ccd2206d2572b12ff2ad8efe6b1370c580898f.tar.gz
Enforce strict 'subs' in multideref optimisation
The code that checks constant keys and turns them into HEKs swallowed the OP_CONST before the strictness checker could get to it, thus allowing barewords when they should not be.
-rw-r--r--op.c7
-rw-r--r--t/lib/strict/subs10
2 files changed, 17 insertions, 0 deletions
diff --git a/op.c b/op.c
index ee31adcb57..28500e31c2 100644
--- a/op.c
+++ b/op.c
@@ -2343,6 +2343,13 @@ S_check_hash_fields_and_hekify(pTHX_ UNOP *rop, SVOP *key_op)
continue;
svp = cSVOPx_svp(key_op);
+ /* make sure it's not a bareword under strict subs */
+ if (key_op->op_private & OPpCONST_BARE &&
+ key_op->op_private & OPpCONST_STRICT)
+ {
+ no_bareword_allowed((OP*)key_op);
+ }
+
/* Make the CONST have a shared SV */
if ( !SvIsCOW_shared_hash(sv = *svp)
&& SvTYPE(sv) < SVt_PVMG
diff --git a/t/lib/strict/subs b/t/lib/strict/subs
index 095adee4cf..bad22c6a46 100644
--- a/t/lib/strict/subs
+++ b/t/lib/strict/subs
@@ -458,3 +458,13 @@ use strict 'subs';
EXPECT
Bareword "FOO" not allowed while "strict subs" in use at - line 3.
Execution of - aborted due to compilation errors.
+########
+# [perl #126981] Strict subs vs. multideref
+sub CONST () { 'some_key' }
+my $h;
+my $v1 = $h->{+CONST_TYPO};
+use strict 'subs';
+my $v2 = $h->{+CONST_TYPO};
+EXPECT
+Bareword "CONST_TYPO" not allowed while "strict subs" in use at - line 6.
+Execution of - aborted due to compilation errors.