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

Variable return types cause an error #2707

Open
p6rt opened this issue Apr 8, 2012 · 8 comments
Open

Variable return types cause an error #2707

p6rt opened this issue Apr 8, 2012 · 8 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Apr 8, 2012

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

Searchable as RT112344$

@p6rt
Copy link
Author

p6rt commented Apr 8, 2012

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 <anon> at testcase.pl​:5

:​:T correctly contains Int, though.

@p6rt
Copy link
Author

p6rt commented Apr 8, 2012

From spidermario@free.fr

testcase.pl

@p6rt
Copy link
Author

p6rt commented Jun 9, 2013

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 :&#8203;: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&#8203;: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
Copy link
Author

p6rt commented Jun 9, 2013

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

@p6rt
Copy link
Author

p6rt commented Jan 18, 2016

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 <unit> at /tmp/HqdmxVFmny
# line 1␤␤»

@p6rt
Copy link
Author

p6rt commented Feb 11, 2016

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 <unit> 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 <unit> 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 <unit> at -e line 1

@p6rt
Copy link
Author

p6rt commented Oct 30, 2016

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 <unit> 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 <unit> 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
Copy link
Author

p6rt commented Oct 30, 2016

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

@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
Labels
Projects
None yet
Development

No branches or pull requests

1 participant