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

Owner: Nobody
Requestors: skaji [at] outlook.com
Cc:
AdminCc:

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



Date: Thu, 8 Oct 2015 23:49:14 +0900
Subject: [BUG] self in Class.^add_method is not a Class object
To: rakudobug [...] perl.org
From: Shoichi Kaji <skaji [...] outlook.com>
Download (untitled) / with headers
text/plain 517b
(Note that the script is also at https://gist.github.com/shoichikaji/e0baf95e6f602a443f16 ) Following script exits with error: $ cat test.p6 class A {} class B { sub foo(A $a) {} A.^add_method('bar', method () { foo(self); }); } $ perl6 -v This is perl6 version 2015.09-289-g6f31121 built on MoarVM version 2015.09-69-g741cb9c $ perl6 test.p6 ===SORRY!=== Error while compiling test.p6 Calling foo(B) will never work with declared signature (A $a) at test.p6:6 ------> ⏏foo(self);
Hi, I think that is more like a parsing problem, because the "self" in the method in general is clearly the right object: class A {} class B { sub foo(A $a) {} A.^add_method('bar', method () { say self.perl; #foo(self); }); } A.new.bar; # > A.new A possible workaround is: class A {} class B { sub foo(A $a) { say $a.perl} A.^add_method('bar', method () { my $a = self; foo($a); }); } A.new.bar # > A.new Don't know if that helps. On Thu Oct 08 07:49:41 2015, skaji@outlook.com wrote: Show quoted text
> (Note that the script is also at > https://gist.github.com/shoichikaji/e0baf95e6f602a443f16 ) > > Following script exits with error: > > $ cat test.p6 > class A {} > > class B { > sub foo(A $a) {} > A.^add_method('bar', method () { > foo(self); > }); > } > > > $ perl6 -v > This is perl6 version 2015.09-289-g6f31121 built on MoarVM version > 2015.09-69-g741cb9c > > $ perl6 test.p6 > ===SORRY!=== Error while compiling test.p6 > Calling foo(B) will never work with declared signature (A $a) > at test.p6:6 > ------> ⏏foo(self);


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