Subject: | missing curly brackets in attribute declaration can lead to segmentation fault |
Date: | Tue, 10 Jul 2012 11:50:42 +0100 |
To: | bug-Moose [...] rt.cpan.org |
From: | Frank Schwach <fs5 [...] sanger.ac.uk> |
Perl
5.8.8
Moose
2.0603
my OS:
Linux version 2.6.32-bpo.4-amd64 (Debian 2.6.32-11~bpo50+1)
How to replicate:
package TestMe;
use warnings;
use strict;
use Moose;
has atr => (
isa => 'Integer',
is => 'ro',
required => 0,
lazy => 1,
default => sub {
my $self = shift;
return $self->foo if $self->foo ;
);
__PACKAGE__->meta->make_immutable;
1;
run it:
$ perl -MTestMe -e "TestMe->new"
Segmentation fault
The real error, the missing curly bracket that should end the default
"sub" block, is not detected and I get a seg fault instead.
This only happens when trying to make immutable and only if I use
"return $self->foo if $self->foo ;"
Changing that line to
"return $self->foo;"
gives me:
$ perl -MTestMe -e "TestMe->new"
panic: pad_swipe curpad at TestMe.pm line 24.
Compilation failed in require.
BEGIN failed--compilation aborted.
which is still a bit opaque but at least it's clearly a compilation
error now. This is probably a very rare case but the resulting error is
very weird indeed.
Thanks for looking into this!
Frank
--
The Wellcome Trust Sanger Institute is operated by Genome Research
Limited, a charity registered in England with number 1021457 and a
company registered in England with number 2742969, whose registered
office is 215 Euston Road, London, NW1 2BE.