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

Typename declared via type capture does not work in return type constraint #6464

Open
p6rt opened this issue Aug 22, 2017 · 2 comments
Open

Comments

@p6rt
Copy link

p6rt commented Aug 22, 2017

Migrated from rt.perl.org#131948 (status was 'new')

Searchable as RT131948$

@p6rt
Copy link
Author

p6rt commented Aug 22, 2017

From @smls

  ➜ sub f (​::T --> T) { T.new }
  ➜ f Int;
  Died with X​::TypeCheck​::Return
  in sub f at [...]

The type alias T works just fine in the rest of the subroutine signature
and body; just not inside the return type constraint, and also not in
the return type constraint of any nested subroutine​:

  ➜ sub f (​::T) { sub g (--> T) { T.new } }
  ➜ say f(Int)();
  Died with X​::TypeCheck​::Return
  in sub g at [...]

The alternative `returns T` and `of T` syntaxes suffer from the same
problem.

@usev6
Copy link

usev6 commented Oct 7, 2023

This seems to work nowadays:

$ ./rakudo-m -e 'sub f (::T --> T) { T.new }; say(f Int)'
0
$ ./rakudo-m -e 'sub f (::T) { sub g (--> T) { T.new } }; say f(Int)()'
0

And the return type constraint also seems to apply:

$ ./rakudo-m -e 'sub f (::T --> T) { 42 }; say(f Int)'
42
$ ./rakudo-m -e 'sub f (::T --> T) { "foo" }; say(f Int)'
Type check failed for return value; expected Int but got Str ("foo")
  in sub f at -e line 1
  in block <unit> at -e line 1

Tagging "testneeded".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants