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

Owner: Nobody
Requestors: supernovus <2010 [at] huri.net>
Cc:
AdminCc:

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



Subject: Methods added to Any don't propagate to derived classes
Date: Tue, 6 Nov 2012 13:09:02 -0800
To: rakudobug [...] perl.org
From: Timothy Totten <2010 [...] huri.net>
Download (untitled) / with headers
text/plain 500b
If you add methods to Any, say using the "augment" feature, or the MOP, the methods don't propagate to derived classes.

For example:

use MONKEY_TYPING;
augment class Any {
  method foo {
    say "hello world";
  }
}

"blah".foo;

# OUTPUT: «No such method 'hello' for invocant of type 'Str'␤  in block  at /tmp/_H_vJIBsA8:1␤␤»

I tried using Any.add_method() instead of augment, and had the same results.

The augment code above works in Niecza and it is the consensus that it should work.

RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 831b
On Tue Nov 06 13:09:28 2012, supernovus wrote: Show quoted text
> If you add methods to Any, say using the "augment" feature, or the MOP, the > methods don't propagate to derived classes. > > For example: > > use MONKEY_TYPING; > augment class Any { > method foo { > say "hello world"; > } > } > > "blah".foo; > > # OUTPUT: «No such method 'hello' for invocant of type 'Str'␤ in block at > /tmp/_H_vJIBsA8:1␤␤» > > I tried using Any.add_method() instead of augment, and had the same results. > > The augment code above works in Niecza and it is the consensus that it > should work.
The workaround, btw, is to re-compose the inherited class - this works, e.g: use MONKEY-TYPING; augment class Any { method foo { say "hello world"; } } Str.^compose; "blah".foo; -- Will "Coke" Coleda


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