Skip Menu |
Report information
Id: 130364
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: TimTom <tim.bollman [at] live.com>
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] Cannot use type parameter to constrain return value
From: Tim Bollman <Tim.Bollman [...] live.com>
Date: Fri, 16 Dec 2016 22:15:26 +0000
To: "rakudobug [...] perl.org" <rakudobug [...] perl.org>
Download (untitled) / with headers
text/plain 633b

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';




This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org