Closed p5pRT closed 6 years ago
Mixing signatures with lvalue subs:
$ perl5.26.0 -Mexperimental=signatures -lwe 'our @a = qw(wibble wobble wabble); sub foo ($i = return substr($a[0]\, -1\, 1)) :lvalue { return substr($a[$i]\, 1\, 1); } print "@a"; foo(2) = "u"; print "@a"; foo() = "y"; print "@a"' wibble wobble wabble wibble wobble wubble Can't return a temporary from lvalue subroutine at -e line 1.
Observe that returning a substr() lvalue works fine in the main block of the subroutine body\, but it fails when done from a default expression in the signature. Returning from inside the signature is legal\, and works fine for non-lvalue subs.
The cause is that the substr op gets a flag set at compile time to indicate whether it needs to yield an lvalue\, and when it's the child of a return op that flag gets set depending on the CvLVALUE flag\, and with attributes being in their present grammatical location that flag doesn't get set early enough to affect compilation of code in the signature. The equivalent code works just fine on the original version of signatures:
$ perl5.20.0 -Mexperimental=signatures -lwe 'our @a = qw(wibble wobble wabble); sub foo :lvalue ($i = return substr($a[0]\, -1\, 1)) { return substr($a[$i]\, 1\, 1); } print "@a"; foo(2) = "u"; print "@a"; foo() = "y"; print "@a"' wibble wobble wabble wibble wobble wubble wibbly wobble wubble
There are also other ops affected by lvalueness\, which will be broken in much the same way. At a quick look\, I think the other built-in attributes don't affect anything in this manner\, but I'm not entirely sure. Non-built-in attributes aren't applied to a sub early enough for this ordering issue to matter. Of some relevance\, last year when we were discussing the possibilities for suppressing @_ where arguments are being accessed in better ways\, I suggested using an attribute to control it and processing attributes earlier to let @_ uses be compile-time errors\, but then observed that the grammatical swap breaks that plan. See \https://www.nntp.perl.org/group/perl.perl5.porters/2016/04/msg235925.html.
@iabyn - Status changed from 'new' to 'resolved'
On Thu\, Sep 21\, 2017 at 01:38:17PM -0700\, Zefram wrote:
Mixing signatures with lvalue subs:
$ perl5.26.0 -Mexperimental=signatures -lwe 'our @a = qw(wibble wobble wabble); sub foo ($i = return substr($a[0]\, -1\, 1)) :lvalue { return substr($a[$i]\, 1\, 1); } print "@a"; foo(2) = "u"; print "@a"; foo() = "y"; print "@a"' wibble wobble wabble wibble wobble wubble Can't return a temporary from lvalue subroutine at -e line 1.
Fixed in 5.27.8. Resolving.
-- The Enterprise successfully ferries an alien VIP from one place to another without serious incident. -- Things That Never Happen in "Star Trek" #7
Then the question is "why are they still 'experimental' in 5,30?" Is there anything needed to help with resolution, so that they can become mainstream in 5.32?
See the current a big discussion on the p5p mailing list entitled "Jumbo Signatures extensions discussion".
Migrated from rt.perl.org#132141 (status was 'resolved')
Searchable as RT132141$