Skip Menu |
Report information
Id: 66892
Status: resolved
Priority: 0/
Queue: perl6

Owner: jnthn [at] jnthn.net
Requestors: masak <cmasak [at] gmail.com>
Cc: timk <timk [at] jtimothyking.com>
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] cannot return an Array with Strs from a sub that declares a return type of Array of Str in Rakudo
Date: Tue, 23 Jun 2009 12:14:50 +0200
To: rakudobug [...] perl.org
From: Carl Mäsak <cmasak [...] gmail.com>
Download (untitled) / with headers
text/plain 428b
<masak> rakudo: sub foo(--> Array of Str) { my Str @a = <foo bar baz>; @a }; foo <p6eval> rakudo 10f223: OUTPUT«Use of type object as value␤Type check failed on return value␤in sub foo [...] * masak submits rakudobug I might have misunderstood something -- but if this isn't the way to declare "I want this sub to return an array of Str", and then to return an Array of Str (look, it's even typed as that!), then what is?
Download (untitled) / with headers
text/plain 177b
NOM returns array of strings as expected bbkr:nom bbkr$ ./perl6 -e 'sub foo(--> Array of Str) { my Str @a = <foo bar baz>; @a }; foo.perl.say' Array.new("foo", "bar", "baz")
Download (untitled) / with headers
text/plain 212b
But does not check subtypes as expected, this should not pass: bbkr:nom bbkr$ ./perl6 -e 'sub foo(--> Array of Str) { my Str @a = "foo", "bar", "baz", 666; @a }; foo.perl.say' Array.new("foo", "bar", "baz", 666)
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 957b
On Sat Sep 10 17:09:52 2011, bbkr wrote: Show quoted text
> But does not check subtypes as expected, this should not pass: > > bbkr:nom bbkr$ ./perl6 -e 'sub foo(--> Array of Str) { my Str @a = > "foo", "bar", "baz", 666; @a }; foo.perl.say' > Array.new("foo", "bar", "baz", 666)
We've lost ground here: $ cat strings.pl sub foo(--> Array of Str) { my Str @a = <foo bar baz>; @a }; foo.perl.say $ ./perl6 strings.pl Type check failed for return value; expected 'Array+{TypedArray}' but got 'Array+{TypedArray}' in sub foo at strings.pl:3 in block at strings.pl:5 $ cat mixed.pl sub foo(--> Array of Str) { my Str @a = "foo", "bar", 123; @a }; foo.perl.say $ ./perl6 mixed.pl Type check failed for return value; expected 'Array+{TypedArray}' but got 'Array+{TypedArray}' in sub foo at mixed.pl:3 in block at mixed.pl:5 strings.pl shouldn't be failing on the return, and mixed.pl should be failing on the assignment. -- Will "Coke" Coleda
Download (untitled) / with headers
text/plain 906b
I've observed this with Array[Int] as well, and I'm assuming it's the same with arrays of any type. Now, I've observed it with a non-array type. (I don't know whether it's the same or a separate issue, but it's the same symptom, so I've put the comment here. Feel free to create a separate ticket if it's a different issue.) $ install/bin/perl6 --version This is perl6 version 2013.08-72-g484f089 built on parrot 5.5.0 revision RELEASE_5_5_0 $ install/bin/perl6 Show quoted text
> sub f (Int $n --> Bool) { return $n == 3; }
sub f(Int $n) { ... } Show quoted text
> f(3)
True Show quoted text
> sub g (Int $n --> Bool) { return $n == any(3..5); }
sub g(Int $n) { ... } Show quoted text
> g(3)
Type check failed for return value; expected 'Bool' but got 'Bool' in sub thread_junction at src/gen/CORE.setting:2905 in method AUTOTHREAD at src/gen/CORE.setting:2933 in sub AUTOTHREAD at src/gen/CORE.setting:2967 (Same symptom in Rakudo 2013.08 and in Rakudo-JVM.)
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 597b
On Tue Jun 23 03:15:22 2009, masak wrote: Show quoted text
> <masak> rakudo: sub foo(--> Array of Str) { my Str @a = <foo bar baz>; > @a }; foo > <p6eval> rakudo 10f223: OUTPUT«Use of type object as value␤Type check > failed on return value␤in sub foo [...] > * masak submits rakudobug > > I might have misunderstood something -- but if this isn't the way to > declare "I want this sub to return an array of Str", and then to > return an Array of Str (look, it's even typed as that!), then what is?
It's the correct way, and it's fixed now; test covering this added to roast in b421638. Thanks! /jnthn


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org