Revert change #22520 (optimise away my $foo = undef and similar
Rafael Garcia-Suarez [Wed, 30 Nov 2005 09:53:11 +0000 (09:53 +0000)]
constructs), in order to fix bug perl #37776
p4raw-link: @22520 on //depot/perl: b9d46b3942a9a8cce9cbca1e08f61ac23083a740

p4raw-id: //depot/perl@26226

op.c
t/op/my.t

diff --git a/op.c b/op.c
index aeedab9..6e37131 100644 (file)
--- a/op.c
+++ b/op.c
@@ -3300,15 +3300,6 @@ Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right)
            /* Result of assignment is always 1 (or we'd be dead already) */
            return newSVOP(OP_CONST, 0, newSViv(1));
        }
-       /* optimise C<my @x = ()> to C<my @x>, and likewise for hashes */
-       if ((left->op_type == OP_PADAV || left->op_type == OP_PADHV)
-               && right->op_type == OP_STUB
-               && (left->op_private & OPpLVAL_INTRO))
-       {
-           op_free(right);
-           left->op_flags &= ~(OPf_REF|OPf_SPECIAL);
-           return left;
-       }
        curop = list(force_list(left));
        o = newBINOP(OP_AASSIGN, flags, list(force_list(right)), curop);
        o->op_private = (U8)(0 | (flags >> 8));
@@ -5802,19 +5793,6 @@ Perl_ck_sassign(pTHX_ OP *o)
            return kid;
        }
     }
-    /* optimise C<my $x = undef> to C<my $x> */
-    if (kid->op_type == OP_UNDEF) {
-       OP * const kkid = kid->op_sibling;
-       if (kkid && kkid->op_type == OP_PADSV
-               && (kkid->op_private & OPpLVAL_INTRO))
-       {
-           cLISTOPo->op_first = NULL;
-           kid->op_sibling = NULL;
-           op_free(o);
-           op_free(kid);
-           return kkid;
-       }
-    }
     return o;
 }
 
index d219f80..6a477db 100755 (executable)
--- a/t/op/my.t
+++ b/t/op/my.t
@@ -1,6 +1,6 @@
 #!./perl
 
-print "1..34\n";
+print "1..36\n";
 
 sub foo {
     my($a, $b) = @_;
@@ -120,3 +120,13 @@ eval { foo3(); foo3(); };
 print "not " if $@;
 print "ok 34\n";
 
+# my $foo = undef should always assign [perl #37776]
+{
+    my $count = 35;
+    loop:
+    my $test = undef;
+    print "not " if defined $test;
+    print "ok $count\n";
+    $test = 42;
+    goto loop if ++$count < 37;
+}