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

Owner: Nobody
Requestors: cpan [at] zoffix.com
Cc:
AdminCc:

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



Subject: [BUG] Can't assign to `int` private attribute using signature
Download (untitled) / with headers
text/plain 385b
#Doesn't work: <TestNinja> m: class { has int $!n = 0; method x ($!n) {} }.new.x: 42 <camelia> rakudo-moar 2c95f7: OUTPUT«Cannot modify an immutable int␤ in method x at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤» # But does, if we use a temp var: <TestNinja> m: class { has int $!n = 0; method x ($n) {$!n = $n} }.new.x: 42 <camelia> rakudo-moar 2c95f7: ( no output )
Date: Thu, 15 Sep 2016 21:26:15 +0200
To: "Zoffix Znet (via RT)" <perl6-bugs-followup [...] perl.org>
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
Subject: Re: [perl #129278] [BUG] Can't assign to `int` private attribute using signature
Download (untitled) / with headers
text/plain 877b
This is a known issue, as there is no native support for attribute binding this way. There’s quite some code in the setting working around this issue :-( Show quoted text
> On 15 Sep 2016, at 20:49, Zoffix Znet (via RT) <perl6-bugs-followup@perl.org> wrote: > > # New Ticket Created by Zoffix Znet > # Please include the string: [perl #129278] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=129278 > > > > #Doesn't work: > <TestNinja> m: class { has int $!n = 0; method x ($!n) {} }.new.x: 42 > <camelia> rakudo-moar 2c95f7: OUTPUT«Cannot modify an immutable int␤ in method x at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤» > > # But does, if we use a temp var: > <TestNinja> m: class { has int $!n = 0; method x ($n) {$!n = $n} }.new.x: 42 > <camelia> rakudo-moar 2c95f7: ( no output )
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 659b
On Thu Sep 15 11:49:35 2016, cpan@zoffix.com wrote: Show quoted text
> #Doesn't work: > <TestNinja> m: class { has int $!n = 0; method x ($!n) {} }.new.x: 42 > <camelia> rakudo-moar 2c95f7: OUTPUT«Cannot modify an immutable int␤ > in method x at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤» >
I've fixed this and added tests to S12-methods/attribute-params.t. It works for named parameters too. So in terms of the originally reported issue this ticket could be considered done. But. Unfortunately, the moment you have a role instead of a class, or a a more complex signature (for example, involving an unpack), it fails. So, some more work and tests needed.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 871b
For the records: This fails on JVM (has to be fixed in src/vm/jvm/runtime/org/perl6/rakudo/Binder.java, probabaly): $ ./perl6-j -e 'class { has int $!n = 0; method x ($!n) {} }.new.x: 42' org.perl6.nqp.sixmodel.reprs.P6OpaqueBaseInstance$BadReferenceRuntimeException: Cannot access a native attribute as a reference attribute in method x at -e line 1 in block <unit> at -e line 1 Tests that use the new method SeqNextNFromIterator fail due to this problem. From S32-list/head.t: $ ./perl6-j -e 'my $list = <a b b c>; say $list.head(3)' org.perl6.nqp.sixmodel.reprs.P6OpaqueBaseInstance$BadReferenceRuntimeException: Cannot access a native attribute as a reference attribute in block <unit> at -e line 1 This works, if one doesn't use a native here: https://github.com/rakudo/rakudo/blob/2c681c55520d34750663cdec2fefcf3005ee550e/src/core/Rakudo/Internals.pm#L266
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 341b
On Sat Oct 15 00:31:09 2016, bartolin@gmx.de wrote: Show quoted text
> [...] > Tests that use the new method SeqNextNFromIterator fail due to this > problem. From S32-list/head.t:
Again, for the records: lizmat++ put in a bandaid for rakudo-j with Rakudo commit 666128fc6e. The tests from S32-list/head.t run fine, but the underlying problem is still there.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 890b
On Tue, 18 Oct 2016 08:39:21 -0700, bartolin@gmx.de wrote: Show quoted text
> > Again, for the records: lizmat++ put in a bandaid for rakudo-j with > Rakudo commit 666128fc6e. The tests from S32-list/head.t run fine, but > the underlying problem is still there.
The bandaid was remove recently (Rakudo commit e8f938b0f6) after psch++ implemented attribute parameter binding on the JVM. So we are back to what jnthn said about roles or more complex signatures: On Wed, 21 Sep 2016 06:30:00 -0700, jnthn@jnthn.net wrote: Show quoted text
> I've fixed this and added tests to S12-methods/attribute-params.t. It > works for named parameters too. So in terms of the originally reported > issue this ticket could be considered done. > > But. > > Unfortunately, the moment you have a role instead of a class, or a a > more complex signature (for example, involving an unpack), it fails. > So, some more work and tests needed.


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