Change 34921 by [EMAIL PROTECTED] on 2008/11/26 18:18:44

        Subject: Addendum to bug #38809: fix assertion failure, more tests
        From: Vincent Pit <[EMAIL PROTECTED]>
        Date: Wed, 26 Nov 2008 18:49:48 +0100
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

... //depot/perl/op.c#1029 edit
... //depot/perl/t/op/do.t#21 edit

Differences ...

==== //depot/perl/op.c#1029 (text) ====
Index: perl/op.c
--- perl/op.c#1028~34920~       2008-11-26 08:24:07.000000000 -0800
+++ perl/op.c   2008-11-26 10:18:44.000000000 -0800
@@ -7651,14 +7651,15 @@
     } else {
        for (; kid; kid = kid->op_sibling)
            if ((kid->op_type == OP_NULL)
-               && (kid->op_flags & OPf_SPECIAL)) {
+               && ((kid->op_flags & (OPf_SPECIAL|OPf_KIDS)) == 
(OPf_SPECIAL|OPf_KIDS))) {
                /* This is a do block */
-               OP *op = cUNOPx(kid)->op_first;
-               assert(op && (op->op_type == OP_LEAVE) && (op->op_flags & 
OPf_KIDS));
-               op = cUNOPx(op)->op_first;
-               assert(op->op_type == OP_ENTER && !(op->op_flags & 
OPf_SPECIAL));
-               /* Force the use of the caller's context */
-               op->op_flags |= OPf_SPECIAL;
+               OP *op = kUNOP->op_first;
+               if (op->op_type == OP_LEAVE && op->op_flags & OPf_KIDS) {
+                   op = cUNOPx(op)->op_first;
+                   assert(op->op_type == OP_ENTER && !(op->op_flags & 
OPf_SPECIAL));
+                   /* Force the use of the caller's context */
+                   op->op_flags |= OPf_SPECIAL;
+               }
            }
     }
 

==== //depot/perl/t/op/do.t#21 (xtext) ====
Index: perl/t/op/do.t
--- perl/t/op/do.t#20~34907~    2008-11-24 22:28:40.000000000 -0800
+++ perl/t/op/do.t      2008-11-26 10:18:44.000000000 -0800
@@ -29,7 +29,7 @@
     return $ok;
 }
 
-print "1..32\n";
+print "1..38\n";
 
 # Test do &sub and proper @_ handling.
 $_[0] = 0;
@@ -105,21 +105,40 @@
 ok( $owww eq '', 'last is if not' );
 
 # [perl #38809]
[EMAIL PROTECTED] = (7);
+$x = sub { do { return do { @a } }; 2 }->();
+ok(defined $x && $x == 1, 'return do { } receives caller scalar context');
[EMAIL PROTECTED] = sub { do { return do { @a } }; 2 }->();
+ok("@x" eq "7", 'return do { } receives caller list context');
+
 @a = (7, 8);
 $x = sub { do { return do { 1; @a } }; 3 }->();
-ok(defined $x && $x == 2, 'return do { } receives caller scalar context');
+ok(defined $x && $x == 2, 'return do { ; } receives caller scalar context');
 @x = sub { do { return do { 1; @a } }; 3 }->();
-ok("@x" eq "7 8", 'return do { } receives caller list context');
+ok("@x" eq "7 8", 'return do { ; } receives caller list context');
+
[EMAIL PROTECTED] = (11 .. 15);
+$x = sub { do { return do { 1; @a, @b } }; 3 }->();
+ok(defined $x && $x == 5, 'return do { ; , } receives caller scalar context');
[EMAIL PROTECTED] = sub { do { return do { 1; @a, @b } }; 3 }->();
+ok("@x" eq "7 8 11 12 13 14 15", 'return do { ; , } receives caller list 
context');
+
+$x = sub { do { return do { 1; @a }, do { 2; @b } }; 3 }->();
+ok(defined $x && $x == 5, 'return do { ; }, do { ; } receives caller scalar 
context');
[EMAIL PROTECTED] = sub { do { return do { 1; @a }, do { 2; @b } }; 3 }->();
+ok("@x" eq "7 8 11 12 13 14 15", 'return do { ; }, do { ; } receives caller 
list context');
+
 @a = (7, 8, 9);
 $x = sub { do { do { 1; return @a } }; 4 }->();
 ok(defined $x && $x == 3, 'do { return } receives caller scalar context');
 @x = sub { do { do { 1; return @a } }; 4 }->();
 ok("@x" eq "7 8 9", 'do { return } receives caller list context');
+
 @a = (7, 8, 9, 10);
 $x = sub { do { return do { 1; do { 2; @a } } }; 5 }->();
-ok(defined $x && $x == 4, 'return do { do { } } receives caller scalar 
context');
+ok(defined $x && $x == 4, 'return do { do { ; } } receives caller scalar 
context');
 @x = sub { do { return do { 1; do { 2; @a } } }; 5 }->();
-ok("@x" eq "7 8 9 10", 'return do { do { } } receives caller list context');
+ok("@x" eq "7 8 9 10", 'return do { do { ; } } receives caller list context');
 
 END {
     1 while unlink("$$.16", "$$.17", "$$.18");
End of Patch.

Reply via email to