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

cannot return an Array with Strs from a sub that declares a return type of Array of Str in Rakudo #1096

Closed
p6rt opened this issue Jun 23, 2009 · 8 comments
Labels
Bug

Comments

@p6rt
Copy link

@p6rt p6rt commented Jun 23, 2009

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

Searchable as RT66892$

@p6rt
Copy link
Author

@p6rt p6rt commented Jun 23, 2009

From @masak

<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?

@p6rt
Copy link
Author

@p6rt p6rt commented Jul 29, 2010

@coke - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 9, 2011

From @bbkr

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")

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 11, 2011

From @bbkr

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)

@p6rt
Copy link
Author

@p6rt p6rt commented Aug 20, 2012

From @coke

On Sat Sep 10 17​:09​:52 2011, bbkr wrote​:

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

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 4, 2013

From timk@jtimothyking.com

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

sub f (Int $n --> Bool) { return $n == 3; }
sub f(Int $n) { ... }
f(3)
True
sub g (Int $n --> Bool) { return $n == any(3..5); }
sub g(Int $n) { ... }
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.)

@p6rt
Copy link
Author

@p6rt p6rt commented Mar 5, 2015

From @jnthn

On Tue Jun 23 03​:15​:22 2009, masak wrote​:

<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

@p6rt
Copy link
Author

@p6rt p6rt commented Mar 5, 2015

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

@p6rt p6rt closed this Mar 5, 2015
@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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.