From: John Napiorkowski Date: Fri, 24 Oct 2008 19:19:07 +0000 (+0000) Subject: if a parameterizable constraint get parameterized, and it has a parameterized parent... X-Git-Tag: 0.60~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0c4c2633cfb953d506c3b912662c32ca2f31c57d;p=gitmo%2FMoose.git if a parameterizable constraint get parameterized, and it has a parameterized parent, we need to make sure that the incoming typeparameter is a subtype of the parents type parameter --- diff --git a/lib/Moose/Meta/TypeConstraint/Parameterizable.pm b/lib/Moose/Meta/TypeConstraint/Parameterizable.pm index 674bfcc..0ecaace 100644 --- a/lib/Moose/Meta/TypeConstraint/Parameterizable.pm +++ b/lib/Moose/Meta/TypeConstraint/Parameterizable.pm @@ -51,6 +51,16 @@ sub parameterize { my ($self, $type_parameter) = @_; my $contained_tc = $self->_parse_type_parameter($type_parameter); + + ## The type parameter should be a subtype of the parent's type parameter + ## if there is one. + + if(my $parent = $self->parent) { + if($parent->can('type_parameter')) { + $contained_tc->is_a_type_of($parent->type_parameter) + || Moose->throw_error("$type_parameter is not a subtype of ".$parent->type_parameter); + } + } if ( $contained_tc->isa('Moose::Meta::TypeConstraint') ) { my $tc_name = $self->name . '[' . $contained_tc->name . ']';