I ran into a problem at the weekend and reduced it to a fragment and
then looked at alternatives.
The problem is in snippet bug2_2 below. There is a type check that
fails, but the types appear to be the same. This may be an existing bug.
The problem is that when I put the return type in the sub signature, the
type checker does not appear to accept the array type, but the snippet
works fine without the return type being specified.
Also, I am confused about what an "Array of A" is, if it is not an array
of elements each of which are A, see bug_4.
The following is from my terminal, running Ubutu:
$perl6 -v
This is perl6 version 2013.09 built on parrot 5.5.0 revision 0
$ for a in 1 2 3 4; do echo; echo "cat bug_$a.p6:"; cat bug_$a.p6; echo
"result of: perl6 bug_$a.p6"; perl6 bug_$a.p6; done;
cat bug_1.p6:
class A { has $.a };
sub one { my A @rv = gather for 1..3 { take A.new( :a($_) ) }; return @rv }
my %x; %x<syms> = one; %x.say;
result of: perl6 bug_1.p6
("syms" => Array[A].new(A.new(a => 1), A.new(a => 2), A.new(a => 3))).hash
cat bug_2.p6:
class A { has $.a };
sub one ( --> Array of A ) { my A @rv = gather for 1..3 { take A.new(
:a($_) ) }; return @rv }
my %x; %x<syms> = one; %x.say;
result of: perl6 bug_2.p6
Type check failed for return value; expected 'Array[A]' but got 'Array[A]'
in sub one at bug_2.p6:2
in block at bug_2.p6:3
cat bug_3.p6:
class A { has $.a };
sub one { my @rv = gather for 1..3 { take A.new( :a($_) ) }; return @rv }
my %x; %x<syms> = one; %x.say;
result of: perl6 bug_3.p6
("syms" => [A.new(a => 1), A.new(a => 2), A.new(a => 3)]).hash
cat bug_4.p6:
class A { has $.a };
sub one ( --> Array of A ) { my @rv = gather for 1..3 { take A.new(
:a($_) ) }; return @rv }
my %x; %x<syms> = one; %x.say;
result of: perl6 bug_4.p6
Type check failed for return value; expected 'Array[A]' but got 'Array'
in sub one at bug_4.p6:2
in block at bug_4.p6:3
Regards,
Richard (finanalyst)