my $self = shift;
my $metaclass = $self->associated_metaclass;
+ my $class = $self->associated_metaclass->name;
+
# If any of our parents have been made immutable, we are okay to
# inline our own method as long as the parent's constructor class
# is the same as $self.
my $constructor = $transformer->inlined_constructor
or next;
- return ref $constructor eq ref $self;
+ return 1 if ref $constructor eq ref $self;
+
+ my $parent_name = $meta->name;
+ my $constructor_class = ref $constructor;
+ my $self_class = ref $self;
+
+ # This case is fairly unlikely. In most normal cases,
+ # incompatibility between constructor classes will be caught
+ # by the code that fixes metaclass incompatibility in
+ # Moose::Meta::Class. However, if the parent passes a
+ # constructor_class directly to
+ # Parent->meta->make_immutable(), this could happen.
+ warn "Not inlining a constructor for $class. It has a parent class ($parent_name)"
+ . " which was inlined using $constructor_class, but $class is using $self_class\n";
+
+ return 0;
}
if ( my $constructor = $metaclass->find_method_by_name( $self->name ) ) {
my $expected_class = $self->_expected_constructor_class;
if ( $constructor->body != $expected_class->can('new') ) {
- my $class = $metaclass->name;
warn "Not inlining a constructor for $class since it is not"
. " inheriting the default $expected_class constructor\n";
eval "use Test::Output";
plan skip_all => "Test::Output is required for this test" if $@;
-plan tests => 5;
+plan tests => 6;
{
package NotMoose;
'no warning when inheriting from a class that has already made itself immutable'
);
}
+
+{
+ package My::Constructor;
+ use base 'Moose::Meta::Method::Constructor';
+}
+
+{
+ package CustomCons;
+ use Moose;
+
+ CustomCons->meta->make_immutable( constructor_class => 'My::Constructor' );
+}
+
+{
+ package Subclass;
+ use Moose;
+
+ extends 'CustomCons';
+
+ ::stderr_is(
+ sub { Subclass->meta->make_immutable },
+ "Not inlining a constructor for Subclass. It has a parent class (CustomCons) which was inlined using My::Constructor, but Subclass is using Moose::Meta::Method::Constructor\n",
+ 'no warning when inheriting from a class that has already made itself immutable'
+ );
+}