Skip Menu |
Report information
Id: 123835
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: avuserow [at] gmail.com
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



From: Adrian Kreher <avuserow [...] gmail.com>
Date: Sun, 15 Feb 2015 00:09:40 -0800
To: rakudobug [...] perl.org
Subject: Cannot use 'is rw' on optional parameter
Download (untitled) / with headers
text/plain 1.2k
I tried 'sub f($x is rw = 60)', STD parses it but rakudo prohibits it. 'is copy' works. I don't see any obvious reason why it shouldn't work. This is perl6 version 2015.01-141-gfec2339 built on MoarVM version 2015.01-34-g2d7eddb 143936 avuserow | m: sub f($x is rw = 60) {$x++; say $x}; f 143937 +camelia | rakudo-moar 949b80: OUTPUT«?31m===?0mSORRY!?31m===?0m Error while compiling /tmp/L9ZwKOd6I3␤Cannot use 'is rw' on an optional parameter␤at /tmp/L9ZwKOd6I3:1␤------> ␤» 144045 avuserow | std: sub f($x is rw = 60) {$x++; say $x}; f 144046 +camelia | std f9b7f55: OUTPUT«ok 00:00 140m␤» 144058 avuserow | rakudobug? 144141 masak | no, I don't think so. 144149 masak | or, hm. 144210 masak | I don't immediately see what the problem is with using 'is rw' on an optional parameter... 144227 masak | sometimes it doesn't bind with the outside, but that's not a show-stopper. 144253 masak | avuserow: please submit it and we can have a discussion of why it should or should not be possible ;) In the "Parameter traits" section of S06, it mentions about 'is rw' and defaults, saying this should be allowed in some cases. But I'm not sure if that applies to this case or not.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 903b
The relevant sentences from the design docs (S06, introduced with commit 7846594ee4): "Since this option [is rw] forces an argument to be required, it cannot coexist with the ? mark to make an argument optional. (It may, however, be used with = indicating a default, but only if the default expression represents something that is nameable at compile time and that can bind as an lvalue, such as CALLER::<$/> or OUTER::<$_>.)" AFAIU the default value in question (= 60) does not qualify as a valid "is rw"-able expression according to S06. Rakudo makes no difference between parameters made optional with the ? mark or those made optional by providing a default value and simply disallows 'is rw' (introduced with commit 45c44bafbf), e.g.: $ perl6 -e 'sub f($x is rw = OUTER::<$_>) {$x++; say $x}; $_ = 41; f' ===SORRY!=== Error while compiling -e Cannot use 'is rw' on an optional parameter at -e:1
Still reproducible (2017.11,HEAD(e5b660e))

I don't know if it's NYI or @LARRY. I'd put LARRY first, and then one of the LARRYs can turn it into a NYI.

On 2015-08-05 15:25:57, bartolin@gmx.de wrote:
Show quoted text
> The relevant sentences from the design docs (S06, introduced with
> commit 7846594ee4):
>
> "Since this option [is rw] forces an argument to be required, it
> cannot coexist with the ? mark to make an argument optional. (It may,
> however, be used with = indicating a default, but only if the default
> expression represents something that is nameable at compile time and
> that can bind as an lvalue, such as CALLER::<$/> or OUTER::<$_>.)"
>
> AFAIU the default value in question (= 60) does not qualify as a valid
> "is rw"-able expression according to S06.
>
> Rakudo makes no difference between parameters made optional with the ?
> mark or those made optional by providing a default value and simply
> disallows 'is rw' (introduced with commit 45c44bafbf), e.g.:
>
> $ perl6 -e 'sub f($x is rw = OUTER::<$_>) {$x++; say $x}; $_ = 41; f'
> ===SORRY!=== Error while compiling -e
> Cannot use 'is rw' on an optional parameter
> at -e:1




This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org