Subject: | Inconsistent type constraint checking behaviour with optional, named parameter |
Date: | Wed, 05 Nov 2014 16:09:27 +0100 |
To: | bug-Moops [...] rt.cpan.org |
From: | Sven Schober <sven.schober [...] uni-ulm.de> |
Hi!
I stumbled across the following today and just wanted to check, if this
is expected behaviour:
#!/usr/bin/env perl
use Modern::Perl '2014';
use Moops;
use Test::More;
use Test::Exception;
class cPickyConstructor {
method BUILD ( Str :$x, Str :$y? ){ }
fun okFunction ( Str :$x, Str :$y? ){ }
};
class cNotSoPickyConstructor {
method BUILD ( Str :$x, Str|Undef :$y? ){ }
};
dies_ok(
sub {
cPickyConstructor->new( x => "", y => undef)
},
'Constructor complains about `undef` not satisfying `Str`'
);
lives_ok(
sub{
cPickyConstructor::okFunction( x => "", y => undef)
},
'But function does not care'
);
lives_ok(
sub {
cNotSoPickyConstructor->new( x => "", y => undef)
},
'Need to explicitly specify `Undef` as type constraint in constructor'
);
done_testing();
Cheers,
Sven
Message body not shown because it is not plain text.