This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Enforce strict 'subs' in multideref optimisation
authorDagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Mon, 21 Dec 2015 19:25:32 +0000 (19:25 +0000)
committerRicardo Signes <rjbs@cpan.org>
Sun, 17 Jan 2016 02:45:16 +0000 (21:45 -0500)
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.

op.c
t/lib/strict/subs

diff --git a/op.c b/op.c
index ee31adc..28500e3 100644 (file)
--- 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
index 095adee..bad22c6 100644 (file)
@@ -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.