Hi there,

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


Cheers

Martin


> 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';
};

> cat B.pm
use v6;
use A;

class B does R {
    method b { self.r }
}

Reply via email to