Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use 'is rw' on optional parameter #3686

Open
p6rt opened this issue Feb 15, 2015 · 5 comments
Open

Cannot use 'is rw' on optional parameter #3686

p6rt opened this issue Feb 15, 2015 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Feb 15, 2015

Migrated from rt.perl.org#123835 (status was 'open')

Searchable as RT123835$

@p6rt
Copy link
Author

p6rt commented Feb 15, 2015

From avuserow@gmail.com

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.

@p6rt
Copy link
Author

p6rt commented Aug 5, 2015

From @usev6

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

1 similar comment
@p6rt
Copy link
Author

p6rt commented Aug 5, 2015

From @usev6

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

@p6rt
Copy link
Author

p6rt commented Aug 5, 2015

@usev6 - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Dec 3, 2017

From @AlexDaniel

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​:

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

@p6rt p6rt added the at_larry label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant