From 948d23704c370224e484b4083be90fba01a7439e Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 21 Jun 2013 12:54:53 -0700 Subject: [PATCH] Stop fbm_compile from flattening refs References can change their stringification any time, so flattening them ahead of time for efficiency gives incorect results. Also, using a reference constant as the second argument to index would result in the constant itself being flattened, even when used elsewhere. --- t/op/index.t | 12 +++++++++++- util.c | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/t/op/index.t b/t/op/index.t index 8a3479c..ad01408 100644 --- a/t/op/index.t +++ b/t/op/index.t @@ -7,7 +7,7 @@ BEGIN { } use strict; -plan( tests => 114 ); +plan( tests => 116 ); run_tests() unless caller; @@ -217,4 +217,14 @@ is(index('bang', PVBM2), 0, "index isn't confused by format compilation"); is(index("rules 1 & 2", perl), 0, 'second index of the same constant works'); } +# PVBM compilation should not flatten ref constants +use constant riffraff => \our $referent; +index "foo", riffraff; +is ref riffraff, 'SCALAR', 'index does not flatten ref constants'; + +package o { use overload '""' => sub { "foo" } } +bless \our $referent, o::; +is index("foo", riffraff), 0, + 'index respects changes in ref stringification'; + } # end of sub run_tests diff --git a/util.c b/util.c index d8b3d33..e07ae4d 100644 --- a/util.c +++ b/util.c @@ -527,7 +527,7 @@ Perl_fbm_compile(pTHX_ SV *sv, U32 flags) PERL_ARGS_ASSERT_FBM_COMPILE; - if (isGV_with_GP(sv)) + if (isGV_with_GP(sv) || SvROK(sv)) return; if (SvVALID(sv)) -- 2.7.4