Hi,

It's because of the default value of array elements. See the end of this
section: https://docs.perl6.org/language/list#Typing

my @a;
say @a.of.perl; # Mu
say @a.default.perl; # Any
say @a[0]; # (Any)

role Foo {};
my Foo @a;
say @a.of.perl; # Foo
say @a.default.perl; # Foo
say @a[0] # (Foo)

On 2017-01-03 10:59:34 GMT, Martin Barth wrote:
> Hi There,
>
> I am not sure if my RoleType @array; is correct, or if there is a better 
> way to declare such an array. But I find the error that is happening 
> when there are no elements in the array confusing on the first sight. It 
> took me a while to realize that my array was empty and therefore it 
> "means" the class/role itself.
>
>
>  > perl6 -e 'role Foo {method n{...}}; class Bar does Foo {method 
> n{"n"}}; my Foo@a = (); @a.push: Bar.new; say @a[0].n'
> n
>
>  > perl6 -e 'role Foo {method n{...}}; class Bar does Foo {method 
> n{"n"}}; my Foo@a = (); say @a[0].n'
> Method 'n' must be implemented by Foo because it is required by a role
>    in any compose_method_table at gen/moar/m-Metamodel.nqp line 2824
>    in any apply at gen/moar/m-Metamodel.nqp line 2834
>    in any compose at gen/moar/m-Metamodel.nqp line 3006
>    in any make_pun at gen/moar/m-Metamodel.nqp line 1692
>    in any find_method at gen/moar/m-Metamodel.nqp line 1720
>    in block <unit> at -e line 1
>
>  > perl6 -e 'role Foo {method n{...}}; class Bar does Foo {method 
> n{"n"}}; my @a = (); say @a[0].n'
> No such method 'n' for invocant of type 'Any'
>    in block <unit> at -e line 1

Reply via email to