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

Owner: Nobody
Requestors: martin [at] senfdax.de
Cc:
AdminCc:

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



From: Martin Barth <martin [...] senfdax.de>
Date: Wed, 5 Jul 2017 17:47:44 +0200
Subject: [BUG] Private Methods/Attributes in roles do not work as expected
To: rakudobug [...] perl.org
Download (untitled) / with headers
text/plain 1.6k

Hi there,

this is crossposed in the perl6-users mailing list. Since noone stopped me from assuming that this is a bug, i am going to open this now:


Assuming those two files A.pm and B.pm.

The file A.pm contains a class A and a role R with a private-method and a $!private member. (the files are in the end of the e-mail)


1) I am wondering why a role can all its private methods:

> perl6 -I. -e 'use A; use B; my $b = B.new; $b.public-method()'
priv method


2) but can't write its private members:

> perl6 -I. -e 'use A; use B; my $b = B.new; $b.set_private(A.new); $b.r'
No such private method '!!private' for invocant of type 'B'
  in method set_private at /home/martin/.workspace/p6/realerror/A.pm (A) line 24
  in block <unit> at -e line 1

WHEN! the set_private looks like this:

    method set_private(A $a) {
        self!private = $a;
    }


3) It seems to work (well, it gets a error a bit later in $b.r):

> perl6 -I. -e 'use A; use B; my $b = B.new; $b.set_private(A.new); $b.r
'
P6opaque: no such attribute '$!private' in type B when trying to get a value
  in method s at /home/martin/.workspace/p6/realerror/A.pm (A) line 11
  in method s at /home/martin/.workspace/p6/realerror/A.pm (A) line 11
  in method r at /home/martin/.workspace/p6/realerror/A.pm (A) line 6
  in block <unit> at -e line 1

WHEN set_private looks like this:

    method set_private(A $a) {
        $!private = $a;
    }

But method !s seems to be broken now.


I dont get why :( i would expect this to work. :-(

In addition I think the error message is broken: "No such private method '!!private' for invocant of type 'B'" it was differently in 2016.11

Download (untitled) / with headers
text/plain 1.8k
On Wed, 05 Jul 2017 09:09:48 -0700, martin@senfdax.de wrote: Show quoted text
> Hi there, > > this is crossposed in the perl6-users mailing list. Since noone stopped > me from assuming that this is a bug, i am going to open this now: > > > Assuming those two files A.pm and B.pm. > > The file A.pm contains a class A and a role R with a private-method and > a $!private member. (the files are in the end of the e-mail) > > > 1) I am wondering why a role can all its private methods: >
> > perl6 -I. -e 'use A; use B; my $b = B.new; $b.public-method()'
> priv method > > > 2) but can't write its private members: >
> > perl6 -I. -e 'use A; use B; my $b = B.new; $b.set_private(A.new); $b.r'
> No such private method '!!private' for invocant of type 'B' > in method set_private at /home/martin/.workspace/p6/realerror/A.pm > (A) line 24 > in block <unit> at -e line 1 > > WHEN! the set_private looks like this: > > method set_private(A $a) { > self!private = $a; > } > > > 3) It seems to work (well, it gets a error a bit later in $b.r): >
> > perl6 -I. -e 'use A; use B; my $b = B.new; $b.set_private(A.new); $b.r
> ' > P6opaque: no such attribute '$!private' in type B when trying to get a > value > in method s at /home/martin/.workspace/p6/realerror/A.pm (A) line 11 > in method s at /home/martin/.workspace/p6/realerror/A.pm (A) line 11 > in method r at /home/martin/.workspace/p6/realerror/A.pm (A) line 6 > in block <unit> at -e line 1 > > WHEN set_private looks like this: > > method set_private(A $a) { > $!private = $a; > } > > But method !s seems to be broken now. > > > I dont get why :( i would expect this to work. :-( > > In addition I think the error message is broken: "No such private method > '!!private' for invocant of type 'B'" it was differently in 2016.11 >
Hi, what's the full code in A.pm and B.pm files?
Download (untitled) / with headers
text/plain 513b
Show quoted text
> cat A.pm
class A { ... } role R { has A $!private; method r { self!s; } method !s { $!private!s if $!private; # line 12 say $.b; } method !private-method { say "priv method"; } method public-method { self!private-method; } method set_private(A $a) { $!private = $a; } } class A does R { has Str $.b = 'secret'; }; Show quoted text
> cat B.pm
use v6; use A; class B does R { method b { self.r } }
From: Martin Barth <martin [...] senfdax.de>
Date: Thu, 6 Jul 2017 15:45:56 +0200
Subject: Re: [perl #131707] [BUG] Private Methods/Attributes in roles do not work as expected
To: perl6-bugs-followup [...] perl.org
Download (untitled) / with headers
text/plain 2.4k
Show quoted text
> cat A.pm
class A { ... } role R { has A $!private; method r { self!s; } method !s { $!private!s if $!private; # line 12 say $.b; } method !private-method { say "priv method"; } method public-method { self!private-method; } method set_private(A $a) { $!private = $a; } } class A does R { has Str $.b = 'secret'; }; Show quoted text
> cat B.pm
use v6; use A; class B does R { method b { self.r } } Am 06.07.2017 um 15:35 schrieb Zoffix Znet via RT: Show quoted text
> On Wed, 05 Jul 2017 09:09:48 -0700, martin@senfdax.de wrote:
>> Hi there, >> >> this is crossposed in the perl6-users mailing list. Since noone stopped >> me from assuming that this is a bug, i am going to open this now: >> >> >> Assuming those two files A.pm and B.pm. >> >> The file A.pm contains a class A and a role R with a private-method and >> a $!private member. (the files are in the end of the e-mail) >> >> >> 1) I am wondering why a role can all its private methods: >>
>> > perl6 -I. -e 'use A; use B; my $b = B.new; $b.public-method()'
>> priv method >> >> >> 2) but can't write its private members: >>
>> > perl6 -I. -e 'use A; use B; my $b = B.new; $b.set_private(A.new); $b.r'
>> No such private method '!!private' for invocant of type 'B' >> in method set_private at /home/martin/.workspace/p6/realerror/A.pm >> (A) line 24 >> in block <unit> at -e line 1 >> >> WHEN! the set_private looks like this: >> >> method set_private(A $a) { >> self!private = $a; >> } >> >> >> 3) It seems to work (well, it gets a error a bit later in $b.r): >>
>> > perl6 -I. -e 'use A; use B; my $b = B.new; $b.set_private(A.new); $b.r
>> ' >> P6opaque: no such attribute '$!private' in type B when trying to get a >> value >> in method s at /home/martin/.workspace/p6/realerror/A.pm (A) line 11 >> in method s at /home/martin/.workspace/p6/realerror/A.pm (A) line 11 >> in method r at /home/martin/.workspace/p6/realerror/A.pm (A) line 6 >> in block <unit> at -e line 1 >> >> WHEN set_private looks like this: >> >> method set_private(A $a) { >> $!private = $a; >> } >> >> But method !s seems to be broken now. >> >> >> I dont get why :( i would expect this to work. :-( >> >> In addition I think the error message is broken: "No such private method >> '!!private' for invocant of type 'B'" it was differently in 2016.11 >>
> > Hi, what's the full code in A.pm and B.pm files? >


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