develooper Front page | perl.perl5.porters | Postings from October 2014

[perl #123020] Void repeat propagates the calling context to its lhs

From:
Father Chrysostomos
Date:
October 21, 2014 03:21
Subject:
[perl #123020] Void repeat propagates the calling context to its lhs
Message ID:
rt-4.0.18-7949-1413861688-486.123020-75-0@perl.org
# New Ticket Created by  Father Chrysostomos 
# Please include the string:  [perl #123020]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=123020 >


If x with parentheses around the lhs occurs in void context, no matter where it occurs in a sub it will propagate the context in which the sub was called:

$ ./perl -lIlib -e 'sub c { print qw[void scalar list][wantarray + defined wantarray] } sub f { (c())x(c()); print "---"; } f(); $_=f(); () = f() '
void
scalar
---
scalar
scalar
---
list
scalar
---

That’s *weird*.  But what should it do?  Internally, x falls back to scalar repeat when not in list context.  (It doesn’t check explicitly for scalar context.)  So scalar context here would make sense.  (I suspect some instances of the void context result in stack bugs.)

-- 

Father Chrysostomos




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About