Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

Variable return types cause an error #2707

Open p6rt opened 12 years ago

p6rt commented 12 years ago

Migrated from rt.perl.org#112344 (status was 'open')

Searchable as RT112344$

p6rt commented 12 years ago

From spidermario@free.fr

With Rakudo 2012.03-53-g119fe3b (commit 119fe3b5b85fe680aa1a7ea29042a5714e63a402), the following code fails​:

  sub id(Any :​:T $x) returns T {   $x   }

  say id 42;

with the following error message​:

  Type check failed for return value   in sub id at testcase.pl​:1   in block \ at testcase.pl​:5

:​:T correctly contains Int, though.

p6rt commented 12 years ago

From spidermario@free.fr

testcase.pl

p6rt commented 11 years ago

From @coke

On Sun Apr 08 08​:03​:22 2012, spidermario@​free.fr wrote​:

With Rakudo 2012.03-53-g119fe3b (commit 119fe3b5b85fe680aa1a7ea29042a5714e63a402), the following code fails​:

sub id\(Any :​:T $x\) returns T \{
    $x
\}

say id 42;

with the following error message​:

Type check failed for return value
  in sub id at testcase\.pl​:1
  in block \<anon> at testcase\.pl&#8203;:5

:​:T correctly contains Int, though.

Current behavior​:

$ cat a.pm sub id(Any :​:T $x) returns T {   $x }

say id 42;

$ ./perl6 a.pm Cannot type check against type variable T   in any type_check at src/gen/Metamodel.nqp​:305   in sub id at a.pm​:2   in block at a.pm​:5

-- Will "Coke" Coleda

p6rt commented 11 years ago

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

p6rt commented 8 years ago

From @gfldex

sub foo(​::T $t --> T){ T.new }; my Int $i = 42; foo($i);

# OUTPUT«Type check failed for return value; expected T but got Int␤ in # sub foo at /tmp/HqdmxVFmny line 1␤ in block \ at /tmp/HqdmxVFmny # line 1␤␤»

p6rt commented 8 years ago

From @skids

Updated behavior​:

Though it should just work, now at least the error isn't LTA. Also, checked that it happens no matter which method you use to apply the return type.

$ perl6 -e 'sub id(Any :​:T $x) returns T { $x }; say id 42;' Type check failed for return value; expected T but got Int   in sub id at -e line 1   in block \ at -e line 1

$ perl6 -e 'sub id(Any :​:T $x --> T) { $x }; say id 42;' Type check failed for return value; expected T but got Int   in sub id at -e line 1   in block \ at -e line 1

$ perl6 -e 'sub id(Any :​:T $x) of T { $x }; say id 42;' Type check failed for return value; expected T but got Int   in sub id at -e line 1   in block \ at -e line 1

p6rt commented 7 years ago

From @usev6

On Mon Jan 18 06​:00​:47 2016, gfldex wrote​:

sub foo(​::T $t --> T){ T.new }; my Int $i = 42; foo($i);

# OUTPUT«Type check failed for return value; expected T but got Int␤ in # sub foo at /tmp/HqdmxVFmny line 1␤ in block \ at /tmp/HqdmxVFmny # line 1␤␤»

As a status update​: This looks somewhat worse now​:

$ ./perl6-m -e 'sub foo(​::T $t --> T){ 45 }; my Int $i = 42; foo($i);' X​::TypeCheck​::Return exception produced no message   in sub foo at -e line 1   in block \ at -e line 1

$ ./perl6-m --version This is Rakudo version 2016.10-104-gdb61aaa built on MoarVM version 2016.10-27-g196361f implementing Perl 6.c.

p6rt commented 7 years ago

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