Whenever we inline a type constraint, we need to include its inline environment.
Dave Rolsky [Thu, 21 Apr 2011 20:40:08 +0000 (15:40 -0500)]
Test every builtin TC as a simple attr's constraint, and as a native Array trait's member TC.

This thoroughly tests that we are propogating the TC's inline environment properly.

lib/Moose/Meta/Method/Accessor.pm
lib/Moose/Meta/Method/Constructor.pm
lib/Moose/Meta/TypeConstraint/Parameterized.pm
t/type_constraints/util_std_type_constraints.t

index 07d10f0..2bb2708 100644 (file)
@@ -44,8 +44,13 @@ sub _eval_environment {
         '$type_constraint_obj' => \$type_constraint_obj,
         '$type_constraint'     => \(
               $type_constraint_obj
-                  ? $type_constraint_obj->_compiled_type_constraint
-                  : undef
+            ? $type_constraint_obj->_compiled_type_constraint
+            : undef
+        ),
+        (
+            $type_constraint_obj
+            ? %{ $type_constraint_obj->inline_environment }
+            : ()
         ),
     };
 }
index 695b826..3acc738 100644 (file)
@@ -80,6 +80,7 @@ sub _eval_environment {
         '$defaults' => \$defaults,
         '@type_constraints' => \@type_constraints,
         '@type_constraint_bodies' => \@type_constraint_bodies,
+        ( map { %{ $_->inline_environment } } @type_constraints ),
     };
 }
 
index 09c2473..c8c887a 100644 (file)
@@ -72,6 +72,15 @@ sub can_be_inlined {
         && $self->type_parameter->can_be_inlined;
 }
 
+sub inline_environment {
+    my $self = shift;
+
+    return {
+        %{ $self->parameterized_from->inline_environment },
+        %{ $self->type_parameter->inline_environment },
+    };
+}
+
 sub _inline_check {
     my $self = shift;
 
index 51b667c..181d647 100644 (file)
@@ -1028,10 +1028,10 @@ sub test_constraint {
             isa => $type,
         )
     );
+
     $class->add_attribute(
         collection => (
             traits  => ['Array'],
-            is      => 'ro',
             isa     => 'ArrayRef[' . $type->name . ']',
             default => sub { [] },
             handles => { add_to_collection => 'push' },
@@ -1062,7 +1062,7 @@ sub test_constraint {
                 $anon_class->new( simple => $accept );
             },
             undef,
-            "no exception passing $described to constructor"
+            "no exception passing $described to constructor with $name"
         );
 
         is(
@@ -1070,7 +1070,7 @@ sub test_constraint {
                 $anon_class->new()->add_to_collection($accept);
             },
             undef,
-            "no exception passing $described to constructor"
+            "no exception passing $described to native trait push method with $name"
         );
     }
 
@@ -1095,14 +1095,14 @@ sub test_constraint {
             exception {
                 $anon_class->new( simple => $reject );
             },
-            "got exception passing $described to constructor"
+            "got exception passing $described to constructor with $name"
         );
 
         ok(
             exception {
                 $anon_class->new()->add_to_collection($reject);
             },
-            "got exception passing $described to constructor"
+            "got exception passing $described to native trait push method with $name"
         );
     }
 }