# New Ticket Created by Timothy Bollman # Please include the string: [perl #130364] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/Ticket/Display.html?id=130364 >
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';