# New Ticket Created by  Zoffix Znet 
# Please include the string:  [perl #127924]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=127924 >


Currently, if you use explicit keyword `return` to return out of a sub marked 
with `is rw` trait, you still get a read-only value, even though you get a 
read-write one if you omit `return`:

<ZoffixW> m: my %h = foo => 'bar'; sub lookup ($key) is rw { return %h{$key}; 
}; lookup('foo') = 'meow'; say %h;
<camelia> rakudo-moar 1aabef: OUTPUT«Cannot assign to a readonly variable or a 
value␤  in block <unit> at /tmp/buNGUMJLYO line 1␤␤»

To rectify this, `return-rw` keyword exists, BUT it doesn't require the sub to 
have `is rw` trait. Thus, the `is rw` trait's usefulness is narrowed down to 
only subs that rely on implicit returns. It also produces confusion, since an 
average programmer would expect explicit placement of keyword `return` to 
retain the program's behaviour unchanged.

Thus, I propose that when a `return` is called from a sub or method marked with 
`is rw` trait, `return-rw` should be called instead. This makes the train more 
useful and its behavour more predictable.

Relevant IRC discussion: http://irclog.perlgeek.de/perl6/2016-04-18#i_12356836

Reply via email to