Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methods added to Any don't propagate to derived classes #2965

Open
p6rt opened this issue Nov 6, 2012 · 3 comments
Open

Methods added to Any don't propagate to derived classes #2965

p6rt opened this issue Nov 6, 2012 · 3 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Nov 6, 2012

Migrated from rt.perl.org#115618 (status was 'open')

Searchable as RT115618$

@p6rt
Copy link
Author

p6rt commented Nov 6, 2012

From @supernovus

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.

@p6rt
Copy link
Author

p6rt commented May 12, 2016

From @coke

On Tue Nov 06 13​:09​:28 2012, supernovus wrote​:

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

@p6rt
Copy link
Author

p6rt commented May 12, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt added the oo label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant