This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_list(): doc and reorganise complex bool
authorDavid Mitchell <davem@iabyn.com>
Wed, 29 May 2019 10:22:48 +0000 (11:22 +0100)
committerDavid Mitchell <davem@iabyn.com>
Mon, 24 Jun 2019 10:40:06 +0000 (11:40 +0100)
The if statement that scans children applying void context to all except
the last child:

1) document what it does;
2) reorganise it (without changing its logical meaning) to make the next
commit easier.

op.c

diff --git a/op.c b/op.c
index a135a18..77dc177 100644 (file)
--- a/op.c
+++ b/op.c
@@ -2386,10 +2386,22 @@ Perl_list(pTHX_ OP *o)
         do_kids:
             while (kid) {
                 OP *sib = OpSIBLING(kid);
-                if (sib && kid->op_type != OP_LEAVEWHEN)
-                    scalarvoid(kid);
-                else
+                /* Apply void context to all kids except the last, which
+                 * is list. E.g.
+                 *      @a = do { void; void; list }
+                 * Except that 'when's are always list context, e.g.
+                 *      @a = do { given(..) {
+                    *                 when (..) { list }
+                    *                 when (..) { list }
+                    *                 ...
+                    *                }}
+                    */
+                if (!sib)
                     list(kid);
+                else if (kid->op_type == OP_LEAVEWHEN)
+                    list(kid);
+                else
+                    scalarvoid(kid);
                 kid = sib;
             }
             PL_curcop = &PL_compiling;