Skip Menu |

This queue is for tickets about the MooseX-Types CPAN distribution.

Report information
The Basics
Id: 44749
Status: resolved
Priority: 0/
Queue: MooseX-Types

People
Owner: jjnapiork [...] cpan.org
Requestors: bphillips [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: MooseX::Type provided type is mutated when UNION'd with a regular Moose type (represented as a string)
See attached for failing unit test and corresponding patch to make it work. The code that exposes the bug: use MooseX::Types -declare => [qw( MyUnionType MyStr )]; use MooseX::Types::Moose qw(Str Item); subtype MyUnionType, as Str | 'Int'; subtype MyStr, as Str; # this will fail because the Str is now a union type and coercions can not be added to a UNION type coerce MyStr, from Item, via {"$_"};
Subject: 0001-underlying-type-is-converted-to-UNION.patch
diff --git a/lib/MooseX/Types/TypeDecorator.pm b/lib/MooseX/Types/TypeDecorator.pm index 46a3fbd..5e6f951 100644 --- a/lib/MooseX/Types/TypeDecorator.pm +++ b/lib/MooseX/Types/TypeDecorator.pm @@ -18,7 +18,7 @@ use overload( ## is needed for syntax compatibility. Maybe someday we'll all just do ## Or[Str,Str,Int] - my @tc = grep {blessed $_} @_; + my @tc = map { blessed $_ ? $_ : Moose::Util::TypeConstraints::find_or_parse_type_constraint($_) } @_; my $union = Moose::Meta::TypeConstraint::Union->new(type_constraints=>\@tc); return Moose::Util::TypeConstraints::register_type_constraint($union); }, diff --git a/t/16_union_with_simple_type.t b/t/16_union_with_simple_type.t new file mode 100644 index 0000000..8de6fff --- /dev/null +++ b/t/16_union_with_simple_type.t @@ -0,0 +1,10 @@ +use Test::More tests => 1; +use MooseX::Types -declare => [qw( MyUnionType MyStr )]; +use MooseX::Types::Moose qw(Str Item); + +subtype MyUnionType, as Str | 'Int'; +subtype MyStr, as Str; + +eval { coerce MyStr, from Item, via {"$_"} }; + +ok(!$@, 'no error thrown on coerce for Union') or diag $@; -- 1.6.2.1
On Thu Apr 02 10:02:37 2009, bphillips wrote: Show quoted text
> See attached for failing unit test and corresponding patch to make it > work. > > The code that exposes the bug: > > use MooseX::Types -declare => [qw( MyUnionType MyStr )]; > use MooseX::Types::Moose qw(Str Item); > > subtype MyUnionType, as Str | 'Int'; > subtype MyStr, as Str; > > # this will fail because the Str is now a union type and coercions can > not be added to a UNION type > coerce MyStr, from Item, via {"$_"}; >
Sorry for the delayed response. I'm reviewing this and will release an update after I bounce it around a bit. Thanks for the patches! John
Please fix this... It is a complete bug report.
Applied for 0.14. Thank you! -- Rafael
On Fri Jun 26 21:07:03 2009, RKITOVER wrote: Show quoted text
> Applied for 0.14. > > Thank you!
Hey, Please don't apply this yet, it's not ready for prime time since the logic would allow creating union types with strings that are not types, such as: subtype Fail, as Int | 'IDONTEXIST' The problem here is that the logic for validating union types is in Moose::Util::TypeConstraints, not in the Union type constraint subtype. So fix this requires a lot of ugly cut and paste bewteen the two, or the real fix which is to make the Union subtype validate itself. Also, this can have weird effects on recursive types. So please hold off a bit. john
Subject: Re: [rt.cpan.org #44749] MooseX::Type provided type is mutated when UNION'd with a regular Moose type (represented as a string)
Date: Sun, 28 Jun 2009 07:09:44 -0700
To: John Napiorkowski via RT <bug-MooseX-Types [...] rt.cpan.org>
From: Rafael Kitover <rkitover [...] io.com>
The code is: my @tc = map { blessed $_ ? $_ : Moose::Util::TypeConstraints::find_or_parse_type_constraint($_) } @_; So it won't create a TC if it doesn't currently exist (unless it's a union or parameterized tc, perhaps it should be just find_type_constraint.) Will be undef for an invalid TC, those probably need to be grepped out. Doesn't affect typedecorators either. But I can remove it if you like. On Sun, Jun 28, 2009 at 09:30:32AM -0400, John Napiorkowski via RT wrote: Show quoted text
> Queue: MooseX-Types > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=44749 > > > On Fri Jun 26 21:07:03 2009, RKITOVER wrote:
> > Applied for 0.14. > > > > Thank you!
> > Hey, > > Please don't apply this yet, it's not ready for prime time since the > logic would allow creating union types with strings that are not types, > such as: > > subtype Fail, as Int | 'IDONTEXIST' > > The problem here is that the logic for validating union types is in > Moose::Util::TypeConstraints, not in the Union type constraint subtype. > So fix this requires a lot of ugly cut and paste bewteen the two, or > the real fix which is to make the Union subtype validate itself. Also, > this can have weird effects on recursive types. So please hold off a bit. > > john
Eh, I was in there changing the all the croaks to use Moose's throw_error, which is important when people start to make their own exception objects, so I detailed the test case and added a few bits so it should basically fail for anything that would have failed for the old string types. Should be good to go now.