This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #124160] Disable targlex for state var init
authorFather Chrysostomos <sprout@cpan.org>
Thu, 26 Mar 2015 05:55:20 +0000 (22:55 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 26 Mar 2015 05:55:20 +0000 (22:55 -0700)
The targlex optimisation optimises away an assignment to a lexical
variable, having the operator on the rhs write directly to the lexi-
cal itself.  This optimisation has a bug in it (#101640) that causes
$lex = "a $b c" to stringify the result, instead of allowing con-
cat overloding to return something other than a string.  I extended
the optimisation to occur with state variable initialization, in
v5.21.5-366-ga1b22ab, not realising it would make an existing bug
occur more often.  For now, just disable the new optimisation.

op.c
t/opbasic/concat.t

diff --git a/op.c b/op.c
index a07eb05..89bf436 100644 (file)
--- a/op.c
+++ b/op.c
@@ -10476,7 +10476,10 @@ Perl_ck_sassign(pTHX_ OP *o)
                                    | ((kkid->op_private & ~OPpLVAL_INTRO) << 8));
            OP *const first = newOP(OP_NULL, 0);
            OP *const nullop =
+               newCONDOP(0, first, o, other);
+           /* XXX targlex disabled for now; see ticket #124160
                newCONDOP(0, first, S_maybe_targlex(aTHX_ o), other);
+            */
            OP *const condop = first->op_next;
 
             OpTYPE_set(condop, OP_ONCE);
index f020992..9c4cbe2 100644 (file)
@@ -22,7 +22,7 @@ sub ok {
     return $ok;
 }
 
-print "1..30\n";
+print "1..31\n";
 
 ($a, $b, $c) = qw(foo bar);
 
@@ -163,3 +163,9 @@ sub beq { use bytes; $_[0] eq $_[1]; }
     $x .= "-append-";
     ok($x eq "ab-append-", "Appending to something initialized using constant folding");
 }
+
+# [perl #124160]
+package o { use overload "." => sub { $_[0] }, fallback => 1 }
+$o = bless [], "o";
+ok(ref(CORE::state $y = "a $o b") eq 'o',
+  'state $y = "foo $bar baz" does not stringify; only concats');