Skip Menu |

Date: Wed, 11 May 2016 10:00:19 +0200
To: rakudobug [...] perl.org
Subject: [BUG] Cannot assign to a readonly variable or a value
From: Martin Barth <martin [...] senfdax.de>
Download (untitled) / with headers
text/plain 437b
<masak> m: class Strange { has $.env is rw; method reset($env) { $.env = $env } }; my $s = Strange.new; my %env = (1 => 2, 3 => 4); $s.reset(%env); $s.reset(%env) <camelia> rakudo-moar 9c8989: OUTPUT«Cannot assign to a readonly variable or a value␤ in method reset at /tmp/plljs3r5Zt line 1␤ in block <unit> at /tmp/plljs3r5Zt line 1␤␤» <ufobat> soo, it's a bug? <masak> pretty sure it is, yes <masak> care to submit it? :)
Confirmed. Also, the same issue occurs when an Array is used instead of a Hash. Simpler demonstration: class A { has $.x is rw; method a { $.x = [1, 2, 3]; $.x = [1, 2, 3]; # Cannot assign to a readonly variable or a value } } A.new.a; The problem does not occur when `$!x` is used instead of `$.x`. Adding `dd` print statements, yields an interesting observation: class A { has $.x is rw; method a { dd $!x; # Any $!x = Any dd $.x; # Any $!x = Any $.x = [1, 2, 3]; dd $!x; # Array $!x = $[1, 2, 3] dd $.x; # $[1, 2, 3] $.x = [1, 2, 3]; # Cannot assign to a readonly variable or a value } } A.new.a; Apparently, once the `$!x` attribute contains an Array or Hash instance, its public accessor `$.x` no longer returns the mutable item container of the attribute as it should, and instead returns the Array/Hash value directly.
Subject: [BUG] Accessor `$.x` for rw attribute returns immutable value instead of Scalar, if it contains an Array or Hash
Download (untitled) / with headers
text/plain 405b
UPDATE: This only happens when the special `$.attr` accessor syntax (for accessing an attribute of `self`) is used. When the verbose method-form accessor syntax (`self.attr` or `$obj.attr`) is used, the assignment works fine. In fact, that form is bugged in the opposite way: It allows the assignment even if the attribute is *not* marked `is rw`, but that bug is tracked by the separate ticket #128324.


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