From: Jesse Luehrs Date: Sat, 17 Sep 2011 23:01:01 +0000 (-0500) Subject: if a union type has no common ancestors, ->parent should return undef X-Git-Tag: 2.0300~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=86036fe3c7982d2ac07fc1377988d5b2ab43aa13;p=gitmo%2FMoose.git if a union type has no common ancestors, ->parent should return undef --- diff --git a/lib/Moose/Meta/TypeConstraint/Union.pm b/lib/Moose/Meta/TypeConstraint/Union.pm index befc557..e2ed92d 100644 --- a/lib/Moose/Meta/TypeConstraint/Union.pm +++ b/lib/Moose/Meta/TypeConstraint/Union.pm @@ -136,6 +136,8 @@ sub parent { for my $parent ( $first->_collect_all_parents ) { return $parent if all { $_->is_a_type_of($parent) } @rest; } + + return; } sub validate { diff --git a/t/type_constraints/union_types.t b/t/type_constraints/union_types.t index 1aa151a..fb1f789 100644 --- a/t/type_constraints/union_types.t +++ b/t/type_constraints/union_types.t @@ -181,4 +181,17 @@ ok( '(Str|Undef)|(ArrayRef|HashRef) is not a type of Str' ); +type 'SomeType', where { 1 }; +type 'OtherType', where { 1 }; + +my $parentless_union = Moose::Meta::TypeConstraint::Union->new( + type_constraints => [ + find_type_constraint('SomeType'), + find_type_constraint('OtherType'), + ], +); + +is($parentless_union->parent, undef, "no common ancestor gives undef parent"); + + done_testing;