Fix two bugs coercions for union types
[gitmo/Moose.git] / lib / Moose / Meta / TypeConstraint / Union.pm
index 135fe79..41654f6 100644 (file)
@@ -32,9 +32,13 @@ sub new {
     );
 
     $self->_set_constraint(sub { $self->check($_[0]) });
-    $self->coercion(Moose::Meta::TypeCoercion::Union->new(
-        type_constraint => $self
-    ));
+
+    if ( grep { $_->has_coercion } @{ $self->type_constraints } ) {
+        $self->coercion(
+            Moose::Meta::TypeCoercion::Union->new( type_constraint => $self )
+        );
+    }
+
     return $self;
 }