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 use type parameter to constrain return value #5891

Open
p6rt opened this issue Dec 16, 2016 · 1 comment
Open

Cannot use type parameter to constrain return value #5891

p6rt opened this issue Dec 16, 2016 · 1 comment
Labels

Comments

@p6rt
Copy link

p6rt commented Dec 16, 2016

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

Searchable as RT130364$

@p6rt
Copy link
Author

p6rt commented Dec 16, 2016

From tim.bollman@live.com

You cannot use the type provided in a parametric role to constrain the return value of a method. It errors with "X​::TypeCheck​::Return exception produced no message".

use v6;
use Test;

role A[​::B] {
  method build-it(*@​attr) {
  return B.new(|@​attr.Capture);
  }
  method build-it-constrain(*@​attr) returns B {
  return B.new(|@​attr.Capture);
  }
}

class Point {
  has $.x;
  has $.y;
}

plan 2;

lives-ok {
  my Point $p = A[Point].new.build-it(x => 5, y => 10);
}, 'Built without constraint';

lives-ok {
  my Point $p = A[Point].new.build-it-constrain(x => 5, y => 10);
}, 'Built with constraint';

@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