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 empty typed List #948

Closed
p6rt opened this issue Apr 25, 2009 · 5 comments
Closed

Cannot return empty typed List #948

p6rt opened this issue Apr 25, 2009 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Apr 25, 2009

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

Searchable as RT65128$

@p6rt
Copy link
Author

p6rt commented Apr 25, 2009

From @skids

The following work as expected​:

my Num List sub f () { return ("A") };
my Num List sub f () { return (1) };
my List sub f () { return () };

The following dies with "Type check failed on return value"

my Num List sub f () { return () };

And as an aside, type checks seem to be skipped for implicit returns​:

my Num List sub f () { ("A") }; f.say; # says "A"

@p6rt
Copy link
Author

p6rt commented Jun 5, 2009

From @jnthn

On Sat Apr 25 09​:23​:43 2009, bri@​abrij.org wrote​:

The following work as expected​:

my Num List sub f () { return ("A") };
my Num List sub f () { return (1) };
my List sub f () { return () };

The following dies with "Type check failed on return value"

my Num List sub f () { return () };

First, all of these should be compile time failures, since only one type
constraint is allowed. So I've fixed Rakudo now (git 056847f) to point
that out.

I think what you really wanted to write was​:

my List of Num sub f() { ... }

However, that's not quite supported yet in Rakudo (it will be, just not
quite there yet), so the best we can do at the moment is​:

my Positional of Num sub f() { ... }

If you're going to write one of these, you need to return an explicitly
typed list. So this fails>

my Positional of Num sub f() { return (1,2,3) }; f()

And you need to write this​:

my Positional of Num sub f() { my Num @​l = 1,2,3; return @​l; }; f()

Subtyping works too, so you can write​:

my Positional of Num sub f() { my Int @​l = 1,2,3; return @​l; }; f()

But in general, if you're going to be dealing with parametric type
constraints you need to be explicitly typing the data structures too; I
suspect that's not going to change, at least in Perl 6.0.0.

And as an aside, type checks seem to be skipped for implicit returns​:

my Num List sub f () { ("A") }; f.say; # says "A"

Yes, that was a problem. I have fixed that too now, in the same push.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Jun 5, 2009

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

@p6rt
Copy link
Author

p6rt commented Jun 5, 2009

From @jnthn

On Fri Jun 05 07​:29​:16 2009, jnthn@​jnthn.net wrote​:

On Sat Apr 25 09​:23​:43 2009, bri@​abrij.org wrote​:

The following work as expected​:

my Num List sub f () { return ("A") };
my Num List sub f () { return (1) };
my List sub f () { return () };

The following dies with "Type check failed on return value"

my Num List sub f () { return () };

First, all of these should be compile time failures, since only one type
constraint is allowed. So I've fixed Rakudo now (git 056847f) to point
that out.

I think what you really wanted to write was​:

my List of Num sub f() { ... }

However, that's not quite supported yet in Rakudo (it will be, just not
quite there yet), so the best we can do at the moment is​:

my Positional of Num sub f() { ... }

If you're going to write one of these, you need to return an explicitly
typed list. So this fails>

my Positional of Num sub f() { return (1,2,3) }; f()

And you need to write this​:

my Positional of Num sub f() { my Num @​l = 1,2,3; return @​l; }; f()

Subtyping works too, so you can write​:

my Positional of Num sub f() { my Int @​l = 1,2,3; return @​l; }; f()

But in general, if you're going to be dealing with parametric type
constraints you need to be explicitly typing the data structures too; I
suspect that's not going to change, at least in Perl 6.0.0.

And as an aside, type checks seem to be skipped for implicit returns​:

my Num List sub f () { ("A") }; f.say; # says "A"

Yes, that was a problem. I have fixed that too now, in the same push.

Thanks,

Jonathan

Oops, meant to Cc the above explanation to the list the first time.

In addition, finished fixing up completely (as far as I know it needs
fixing up) type checking of implicitly returned values. Plus added tests
to S02-builtin-datatypes/types.t for all issues in this ticket. So,
resolving.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Jun 5, 2009

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

@p6rt p6rt closed this as completed Jun 5, 2009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant