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

Roles can't use stub methods to indicate "must implement" methods: calls to such methods always ambiguous #3795

Closed
p6rt opened this issue Apr 25, 2015 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Apr 25, 2015

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

Searchable as RT124393$

@p6rt
Copy link
Author

p6rt commented Apr 25, 2015

From jepeway@blasted-heath.com

Trying to tell doers of a role that they are expected to implement a method (a là Java interfaces) doesn’t seem to work. This

role A { multi method a(Int $i) {...}; multi method a(Str $s) {...}; }; class B does A { multi method a(Int $i){0}; multi method a(Str $s) {"a"}; } ; B.new.a(0).say

yields​:

Ambiguous call to 'a'; these signatures all match​:
  :(B $​: Int $i, *%_)
  :(B $​: Int $i, *%_)
in block
  <unit> at /tmp/0ILm1pfWyW​:1

Both TimToady and timotimo suspect this to be a bug. See

  http://irclog.perlgeek.de/perl6/2015-04-22#i_10480886

for their discussion.

Chris.

@p6rt
Copy link
Author

p6rt commented Nov 15, 2015

From @autarch

On Sat Apr 25 16​:25​:08 2015, jepeway@​blasted-heath.com wrote​:

Trying to tell doers of a role that they are expected to implement a
method (a là Java interfaces) doesn’t seem to work. This

role A { multi method a(Int $i) {...}; multi method a(Str $s) {...};
}; class B does A { multi method a(Int $i){0}; multi method a(Str $s)
{"a"}; } ; B.new.a(0).say

yields​:

Ambiguous call to 'a'; these signatures all match​:
:(B $​: Int $i, *%_)
:(B $​: Int $i, *%_)
in block
<unit> at /tmp/0ILm1pfWyW​:1

Both TimToady and timotimo suspect this to be a bug. See

http://irclog.perlgeek.de/perl6/2015-04-22#i_10480886

for their discussion.

Chris.

I'd expect this to work even if the role's method wasn't a stub, as I'd expect class methods to always shadow a role method of the same name+signature. However, rakudo gives the same error regardless of whether the role method is a stub or not.

@p6rt
Copy link
Author

p6rt commented Nov 15, 2015

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

@p6rt
Copy link
Author

p6rt commented Nov 15, 2015

From @autarch

On Sat Apr 25 16​:25​:08 2015, jepeway@​blasted-heath.com wrote​:

Trying to tell doers of a role that they are expected to implement a
method (a là Java interfaces) doesn’t seem to work. This

role A { multi method a(Int $i) {...}; multi method a(Str $s) {...};
}; class B does A { multi method a(Int $i){0}; multi method a(Str $s)
{"a"}; } ; B.new.a(0).say

yields​:

Ambiguous call to 'a'; these signatures all match​:
:(B $​: Int $i, *%_)
:(B $​: Int $i, *%_)
in block
<unit> at /tmp/0ILm1pfWyW​:1

Both TimToady and timotimo suspect this to be a bug. See

http://irclog.perlgeek.de/perl6/2015-04-22#i_10480886

for their discussion.

Chris.

I'd also note that contrary to the ticket subject, this _does_ work as expected for non-multis. A stub (non-multi) method in the role forces the consuming class to implement the method.

@p6rt
Copy link
Author

p6rt commented Dec 22, 2015

From @jnthn

On Sun Nov 15 10​:29​:36 2015, autarch wrote​:

On Sat Apr 25 16​:25​:08 2015, jepeway@​blasted-heath.com wrote​:

Trying to tell doers of a role that they are expected to implement a
method (a là Java interfaces) doesn’t seem to work. This

role A { multi method a(Int $i) {...}; multi method a(Str $s) {...};
}; class B does A { multi method a(Int $i){0}; multi method a(Str
$s)
{"a"}; } ; B.new.a(0).say

yields​:

Ambiguous call to 'a'; these signatures all match​:
:(B $​: Int $i, *%_)
:(B $​: Int $i, *%_)
in block
<unit> at /tmp/0ILm1pfWyW​:1

Both TimToady and timotimo suspect this to be a bug. See

http://irclog.perlgeek.de/perl6/2015-04-22#i_10480886

for their discussion.

Chris.

I'd expect this to work even if the role's method wasn't a stub, as
I'd expect class methods to always shadow a role method of the same
name+signature. However, rakudo gives the same error regardless of
whether the role method is a stub or not.

Roles in multis are now handled by considering their signature equ, both for requirements and composition. Tests in S14-roles/composition.t.

@p6rt p6rt closed this as completed Dec 22, 2015
@p6rt
Copy link
Author

p6rt commented Dec 22, 2015

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

@p6rt p6rt added the Bug 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