On Fri Jun 05 07:29:16 2009, jn...@jnthn.net wrote: > On Sat Apr 25 09:23:43 2009, b...@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