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

Role/submethod/attribute WAT #3604

Closed
p6rt opened this issue Dec 10, 2014 · 6 comments
Closed

Role/submethod/attribute WAT #3604

p6rt opened this issue Dec 10, 2014 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Dec 10, 2014

Migrated from rt.perl.org#123407 (status was 'resolved')

Searchable as RT123407$

@p6rt
Copy link
Author

p6rt commented Dec 10, 2014

From @lizmat

[23​:22​:42] <lizmat> m​: role A { has $.a; submethod BUILD(​:$!a) {}}; class B does A {}; B.new # this feels weird
[23​:22​:43] <+camelia> rakudo-moar 5f6494​: OUTPUT«P6opaque​: no such attribute '$!a'␤ in submethod BUILD at /tmp/oXV5w_hmGw​:1␤ in method BUILDALL at src/gen/m-CORE.setting​:961␤ in method bless at src/gen/m-CORE.setting​:944␤ in method new at src/gen/m-CORE.setting​:928␤ in block <unit> at /tmp…»
[23​:23​:16] <lizmat> so I can't have a submethod BUILD in a role ?
[23​:23​:36] <jnthn> lizmat​: What happens if you assign the attr in the method body and take a normal programer?
[23​:23​:39] <jnthn> wtf
[23​:23​:41] <jnthn> a normal PARAMETER
[23​:24​:28] <lizmat> jnthn​: works ok then
[23​:24​:35] <lizmat> ok, that will do as a workaround then
[23​:25​:29] <jnthn> Pleaes file it
[23​:25​:37] <lizmat> will do

@p6rt
Copy link
Author

p6rt commented Dec 10, 2014

From @lizmat

On 10 Dec 2014, at 23​:22, Elizabeth Mattijsen (via RT) <perl6-bugs-followup@​perl.org> wrote​:

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

[23​:22​:42] <lizmat> m​: role A { has $.a; submethod BUILD(​:$!a) {}}; class B does A {}; B.new # this feels weird
[23​:22​:43] <+camelia> rakudo-moar 5f6494​: OUTPUT«P6opaque​: no such attribute '$!a'␤ in submethod BUILD at /tmp/oXV5w_hmGw​:1␤ in method BUILDALL at src/gen/m-CORE.setting​:961␤ in method bless at src/gen/m-CORE.setting​:944␤ in method new at src/gen/m-CORE.setting​:928␤ in block <unit> at /tmp…»
[23​:23​:16] <lizmat> so I can't have a submethod BUILD in a role ?
[23​:23​:36] <jnthn> lizmat​: What happens if you assign the attr in the method body and take a normal programer?
[23​:23​:39] <jnthn> wtf
[23​:23​:41] <jnthn> a normal PARAMETER
[23​:24​:28] <lizmat> jnthn​: works ok then
[23​:24​:35] <lizmat> ok, that will do as a workaround then
[23​:25​:29] <jnthn> Pleaes file it
[23​:25​:37] <lizmat> will do

[23​:25​:56] <jnthn> it's either a generic instantiatoin bug or, more likely perhaps, a bug in the signature bind lowering optimization tht makes it mis-handle the genericity.
[23​:27​:22] <lizmat> --optimize=0 gives same result
[23​:28​:13] <jnthn> Yeah, but it's actually done in actions phase, not optimizer phase.
[23​:28​:17] <lizmat> disabling spesh also doesn't change the result (not that I expected that, but as a data point)
[23​:28​:39] <jnthn> m​: role A { has $.a; submethod BUILD(​:$!a, @​a? is copy) {}}; class B does A {}; B.new
[23​:28​:39] <+camelia> rakudo-moar 5f6494​: OUTPUT«�[31m===�[0mSORRY!�[31m===�[0m Error while compiling /tmp/ncybyPYRO3␤Cannot put optional positional parameter @​a after variadic parameters␤at /tmp/ncybyPYRO3​:1␤------> �[32ms $.a; submethod BUILD(​:$!a, @​a? is copy�[33m⏏�[31m) {}}; class B does A {}…»
[23​:28​:46] <jnthn> ah
[23​:28​:55] <jnthn> m​: role A { has $.a; submethod BUILD(@​a? is copy, :$!a) {}}; class B does A {}; B.new
[23​:28​:56] <+camelia> rakudo-moar 5f6494​: ( no output )
[23​:29​:05] <jnthn> Yeah, it's in the bind lowering.
[23​:29​:30] <jnthn> (I know bind lowering can't handle @​a is copy, so I use it to force it to bail).
[23​:30​:03] lizmat does not know what you mean with "bind lowering"
[23​:30​:27] <jnthn> lizmat​: Signature binding naively goes through a bunch of code that interprets the signature.
[23​:31​:17] <jnthn> lizmat​: Bind lowering "compiles" signatures that are simple enough (which is the majority thta show up in real code)
[23​:31​:48] <jnthn> And the bug is in that bit of compilation, somewhere around the code that handles attributive parameters.

@p6rt
Copy link
Author

p6rt commented Sep 20, 2015

From @skids

At least the original snippet seems to work now​:

05​:10​:38 PM) skids​: m​: role A { has $.a; submethod BUILD(​:$!a) {}}; class B does A {}; B.new.a.say
(05​:10​:38 PM) camelia​: rakudo-moar cab888​: OUTPUT«(Any)␤»
(05​:10​:49 PM) skids​: m​: role A { has $.a; submethod BUILD(​:$!a) {}}; class B does A {}; B.new(​:a(1)).a.say
(05​:10​:49 PM) camelia​: rakudo-moar cab888​: OUTPUT«1␤»

Test added.

@p6rt
Copy link
Author

p6rt commented Sep 20, 2015

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

@p6rt
Copy link
Author

p6rt commented Oct 11, 2015

From @niner

Closing as the original examples all work now and tests have been added.

@p6rt p6rt closed this as completed Oct 11, 2015
@p6rt
Copy link
Author

p6rt commented Oct 11, 2015

@niner - Status changed from 'open' to 'resolved'

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