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

Attribute.package is wrong for attributes declared inside roles #5037

Open
p6rt opened this issue Jan 11, 2016 · 5 comments
Open

Attribute.package is wrong for attributes declared inside roles #5037

p6rt opened this issue Jan 11, 2016 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Jan 11, 2016

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

Searchable as RT127236$

@p6rt
Copy link
Author

p6rt commented Jan 11, 2016

From @LLFourn

role Foo { has $.foo; }; Foo.^attributes[0].package.^name.say #->$?CLASS

@p6rt
Copy link
Author

p6rt commented Jan 11, 2016

From @LLFourn

Since timtimo++ saw this ticket and tried to ping me on IRC I'm going to
explain why I wanted this to work. See​:

https://github.com/LLFourn/p6-AttrX-InitArg/
And in particular this commit.
LLFourn/p6-AttrX-InitArg@ffd5e96

I was using Attribute.package to figure out the class that I should apply
the "InitArgContainer" role to. I found that this didn't work with roles
because $attr.package was a GenericHOW. So instead I used a compiler hack
($*PACKAGE), which worked perfectly.

If MOP introspection doesn't work, compiler introspection will. I think it
would be better if the former had the power so I could avoid the latter.

I think Perl 6 is conflating the notion of a 'package' and a 'class'​:

role Foo { has $.a }; class Bar does Foo { }; Bar.^attributes[0].package.say

#-> Bar

To me that should be Foo. It was declared in Foo. This is important for
introspection related to auto-documentation. If I want to produce
documentation for a class, I want to know where it's attributes and methods
came from, ie which file, which module, in which package.

I'm totally fine if this is NOTABUG for now, I didn't know there was this
theme of roles are not real packages. I knew of course they weren't real
classes ( which is why It was supprising when I found I could .new them!)

LL

On Tue, Jan 12, 2016 at 12​:46 AM Lloyd Fournier <
perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Lloyd Fournier
# Please include the string​: [perl #​127236]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=127236 >

role Foo { has $.foo; }; Foo.^attributes[0].package.^name.say #-&gt;$?CLASS

@p6rt
Copy link
Author

p6rt commented Jan 11, 2016

From @LLFourn

To add to the confusion​:

role Foo { method meth { } }; class Bar does Foo { };
Bar.^find_method("meth").package.say
(Foo)

so methods behave as I expect but attributes don't.

On Tue, Jan 12, 2016 at 2​:00 AM Lloyd Fournier <lloyd.fourn@​gmail.com>
wrote​:

Since timtimo++ saw this ticket and tried to ping me on IRC I'm going to
explain why I wanted this to work. See​:

https://github.com/LLFourn/p6-AttrX-InitArg/
And in particular this commit.

LLFourn/p6-AttrX-InitArg@ffd5e96

I was using Attribute.package to figure out the class that I should apply
the "InitArgContainer" role to. I found that this didn't work with roles
because $attr.package was a GenericHOW. So instead I used a compiler hack
($*PACKAGE), which worked perfectly.

If MOP introspection doesn't work, compiler introspection will. I think it
would be better if the former had the power so I could avoid the latter.

I think Perl 6 is conflating the notion of a 'package' and a 'class'​:

role Foo { has $.a }; class Bar does Foo { };
Bar.^attributes[0].package.say

#-> Bar

To me that should be Foo. It was declared in Foo. This is important for
introspection related to auto-documentation. If I want to produce
documentation for a class, I want to know where it's attributes and methods
came from, ie which file, which module, in which package.

I'm totally fine if this is NOTABUG for now, I didn't know there was this
theme of roles are not real packages. I knew of course they weren't real
classes ( which is why It was supprising when I found I could .new them!)

LL

On Tue, Jan 12, 2016 at 12​:46 AM Lloyd Fournier <
perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Lloyd Fournier
# Please include the string​: [perl #​127236]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=127236 >

role Foo { has $.foo; }; Foo.^attributes[0].package.^name.say #-&gt;$?CLASS

@p6rt
Copy link
Author

p6rt commented Jan 11, 2016

From @jnthn

On Mon Jan 11 05​:46​:19 2016, lloyd.fourn@​gmail.com wrote​:

role Foo { has $.foo; }; Foo.^attributes[0].package.^name.say #-&gt;$?CLASS

Just to note that this behavior is intentional rather than accidental (or at least, *I* intended it :-)). Roles undergo generic instantiation at the point of being composed into a class, during which the package is substituted for the type of the class itself. This is important for things like accessor generation to work, since after composition the attributes need to be resolved as if they really are in the class.

We might want a declaring-package that is non-generic, if there's a strong enough use case. And the method inconsistency may want resolving.

@p6rt
Copy link
Author

p6rt commented Jan 11, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant