Possible regression using constant for hash key in perl 5.22+ #15099
Comments
From @exodistThis is a pattern that is used sometimes
This has a couple benefits, one of which is typo protection for hash key sub CONST() { 'some_key' };
The above will fail on perl 5.8->5.20 with the following error: Bareword "CONST_TYPO" not allowed while "strict subs" in use at However on 5.22 it compiles perfectly fine, and also does not issue any I am attaching a sample script to demonstrate it. |
From @ilmariChad Granum (via RT) <perlbug-followup@perl.org> writes:
This appears to be due to the multideref optimisation silently eating $ perl -MO=Concise -Mstrict -e 'sub CONST() { 'some_key' }; my $h; my $val = $h->{+CONST_TYPO};' If I introduce another check-time error before it, the expected error $ perl -MO=Concise -Mstrict -e 'sub CONST() { 'some_key' }; $wat; my $h; my $val = $h->{+CONST_TYPO};' -- |
The RT System itself - Status changed from 'new' to 'open' |
From @ilmariilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes:
I accidentally a patch: |
From @ilmari0001-perl-126981-Enforce-strict-subs-in-multideref-optimi.patchFrom d8b194076731858f134f68e484f67b6da1377ff3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?D=2E=20Ilmari=20Manns=C3=A5ker?=
<ilmari.mannsaker@net-a-porter.com>
Date: Mon, 21 Dec 2015 19:11:24 +0000
Subject: [PATCH] [perl #126981] 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.
---
op.c | 7 +++++++
t/lib/strict/subs | 10 ++++++++++
2 files changed, 17 insertions(+)
diff --git a/op.c b/op.c
index 0de303c..bc6b15d 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 095adee..bad22c6 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.
--
2.6.2
|
From @ilmari-- |
From @ilmariilmari@ilmari.org (Dagfinn Ilmari Mannsåker) writes:
Please disregard the previous patch, it had the wrong email address in |
From @ilmari0001-perl-126981-Enforce-strict-subs-in-multideref-optimi.patchFrom 0399b344f02eedc9e7cc3fff22acc7c1a6ce917f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Mon, 21 Dec 2015 19:25:32 +0000
Subject: [PATCH] [perl #126981] 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.
---
op.c | 7 +++++++
t/lib/strict/subs | 10 ++++++++++
2 files changed, 17 insertions(+)
diff --git a/op.c b/op.c
index 0de303c..bc6b15d 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 095adee..bad22c6 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.
--
2.6.2
|
From @ilmari-- |
From @jkeenanOn Mon Dec 21 11:27:42 2015, ilmari wrote:
1. It would be nice if someone could run a 'git bisect' to identify the place this regression crept in. 2. Patch appears to have beneficial impact; smoking in smoke-me/jkeenan/ilmari/126981-strict-subs branch. Data: #################### $ perlbrew use perl-5.20.1 $ perlbrew use perl-5.22.0 # blead: # Applying ilmari's patch in smoke-me/jkeenan/ilmari/126981-strict-subs branch restores compile-time failure. -- |
@rjbs - Status changed from 'open' to 'pending release' |
From @khwilliamsonThank you for submitting this report. You have helped make Perl better. Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0 |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#126981 (status was 'resolved')
Searchable as RT126981$
The text was updated successfully, but these errors were encountered: