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

Owner: Nobody
Requestors: masak <cmasak [at] gmail.com>
Cc:
AdminCc:

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



Subject: [BUG] Rakudo allows assignment to elements of a readonly array... except when it doesn't
Date: Tue, 4 May 2010 23:12:38 +0200
To: rakudobug [...] perl.org
From: Carl Mäsak <cmasak [...] gmail.com>
Download (untitled) / with headers
text/plain 778b
<masak> rakudo: sub foo(@a) { @a[1] = "NOES" }; my @a = <OH HAI>; foo(@a); say ~@a <p6eval> rakudo 1eef08: OUTPUT«OH NOES␤» <masak> is this supposed to be allowed? <pmichaud> masak: I haven't seen a clear answer to that question. <masak> pmichaud: ISTR there was some wording in the spec about the readonlyness stretching 'one level down' into arrays/hashes, but I can't find it now, despite trying. <pmichaud> masak: From an implementation perspective, I see nothing but pain in trying to make that happen. <masak> pmichaud: anyway, this already fails: <masak> rakudo: sub foo(@a) { @a[0, 1] = <OH NOES> }; my @a = 0, 1; foo(@a) <p6eval> rakudo 1eef08: OUTPUT«Cannot assign to readonly value [...] <masak> so something is inconsistent, at least. * masak submits rakudobug
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1024b
On Tue May 04 14:13:17 2010, masak wrote: Show quoted text
> <masak> rakudo: sub foo(@a) { @a[1] = "NOES" }; my @a = <OH HAI>; > foo(@a); say ~@a > <p6eval> rakudo 1eef08: OUTPUT«OH NOES␤» > <masak> is this supposed to be allowed? > <pmichaud> masak: I haven't seen a clear answer to that question. > <masak> pmichaud: ISTR there was some wording in the spec about the > readonlyness stretching 'one level down' into arrays/hashes, but I > can't find it now, despite trying. > <pmichaud> masak: From an implementation perspective, I see nothing > but pain in trying to make that happen. > <masak> pmichaud: anyway, this already fails: > <masak> rakudo: sub foo(@a) { @a[0, 1] = <OH NOES> }; my @a = 0, 1; foo(@a) > <p6eval> rakudo 1eef08: OUTPUT«Cannot assign to readonly value [...] > <masak> so something is inconsistent, at least. > * masak submits rakudobug
Behavior changed: Show quoted text
> sub foo(@a) { @a[1] = "NOES" }; my @a = <OH HAI>;
OH HAI Show quoted text
> sub foo(@a) { @a[0, 1] = <OH NOES> }; my @a = 0, 1; foo(@a)
OH NOES -- Will "Coke" Coleda
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.5k
On Sat Oct 20 18:12:38 2012, coke wrote: Show quoted text
> On Tue May 04 14:13:17 2010, masak wrote:
> > <masak> rakudo: sub foo(@a) { @a[1] = "NOES" }; my @a = <OH HAI>; > > foo(@a); say ~@a > > <p6eval> rakudo 1eef08: OUTPUT«OH NOES␤» > > <masak> is this supposed to be allowed? > > <pmichaud> masak: I haven't seen a clear answer to that question. > > <masak> pmichaud: ISTR there was some wording in the spec about the > > readonlyness stretching 'one level down' into arrays/hashes, but I > > can't find it now, despite trying. > > <pmichaud> masak: From an implementation perspective, I see nothing > > but pain in trying to make that happen. > > <masak> pmichaud: anyway, this already fails: > > <masak> rakudo: sub foo(@a) { @a[0, 1] = <OH NOES> }; my @a = 0, 1; > > foo(@a) > > <p6eval> rakudo 1eef08: OUTPUT«Cannot assign to readonly value [...] > > <masak> so something is inconsistent, at least. > > * masak submits rakudobug
> > Behavior changed: >
> > sub foo(@a) { @a[1] = "NOES" }; my @a = <OH HAI>;
> OH HAI >
> > sub foo(@a) { @a[0, 1] = <OH NOES> }; my @a = 0, 1; foo(@a)
> OH NOES
These are now the same (both in nom and glr, even) 12:10 < [Coke]> m: sub foo(@a) { @a[1] = "NOES" }; my @a = <OH HAI>; foo(@a); say ~@a 12:10 <+camelia> rakudo-moar 47ddca: OUTPUT«OH NOES␤» 12:10 < GLRelia> rakudo-moar 345953: OUTPUT«OH NOES␤» 12:11 < [Coke]> m: sub foo(@a) { @a[0, 1] = <OH NOES> }; my @a = 0, 1; foo(@a); say ~@a; 12:11 <+camelia> rakudo-moar 47ddca: OUTPUT«OH NOES␤» 12:11 < GLRelia> rakudo-moar 345953: OUTPUT«OH NOES␤» Closable with tests? -- Will "Coke" Coleda
Download (untitled) / with headers
text/plain 611b
<masak> [Coke]: no. <masak> [Coke]: I think you misunderstood the goal of the ticket. <masak> [Coke]: the spec said (and still *says*, I think) that the *contents* of the array parameter are readonly. that's what the "one level down" thing refers to. <masak> [Coke]: However, the default forces any container argument to also <masak> be treated as an immutable value. This extends down only one level; <masak> an immutable container may always return an element that is mutable if <masak> it so chooses. <masak> S06:718 <synbot6> Link: http://design.perl6.org/S06.html#line_718 * masak adds this to the ticket
RT-Send-CC: perl6-compiler [...] perl.org
On Thu Aug 27 09:22:02 2015, masak wrote: Show quoted text
> <masak> [Coke]: no. > <masak> [Coke]: I think you misunderstood the goal of the ticket. > <masak> [Coke]: the spec said (and still *says*, I think) that the > *contents* of the array parameter are readonly. that's what the "one > level down" thing refers to. > <masak> [Coke]: However, the default forces any container argument to > also > <masak> be treated as an immutable value. This extends down only one > level; > <masak> an immutable container may always return an element that is > mutable if > <masak> it so chooses. > <masak> S06:718 > <synbot6> Link: http://design.perl6.org/S06.html#line_718 > * masak adds this to the ticket
Resolution: not this Christmas. Short discussion: http://irclog.perlgeek.de/perl6/2015-12-16#i_11729677 In my view, the best hope of doing this is probably through some static analysis, which we can introduce conditional on language version, so it'd be opt in by language version and we'd be able to not break existing code that didn't opt in to using that version. For the meantime, the ticket survives, but is off the xmas list.


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