if a union type has no common ancestors, ->parent should return undef
Jesse Luehrs [Sat, 17 Sep 2011 23:01:01 +0000 (18:01 -0500)]
lib/Moose/Meta/TypeConstraint/Union.pm
t/type_constraints/union_types.t

index befc557..e2ed92d 100644 (file)
@@ -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 {
index 1aa151a..fb1f789 100644 (file)
@@ -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;