Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 129729
Status: resolved
Priority: 0/
Queue: Type-Tiny

People
Owner: Nobody in particular
Requestors: djerius [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 1.004004
  • 1.005_000
  • 1.005_001
  • 1.005_002
  • 1.005_003
Fixed in: (no value)



Subject: Union with Enum with a value containing a '-' character fails
The following code use strict; use warnings; use Types::Standard qw[ Bool Enum ]; my $x = Bool | Enum [ 'start-end', 'end' ]; produces an error: Expected R_BRACKET; got TYPE at [...]/lib/site_perl/5.28.1/Type/Parser.pm line 391. Changing the '-' in 'start-end' to any other character (well, any that I've tried!) makes it behave.
On Sat Jun 01 21:30:22 2019, DJERIUS wrote: Show quoted text
> The following code > > use strict; > use warnings; > > use Types::Standard qw[ Bool Enum ]; > > my $x = Bool | Enum [ 'start-end', 'end' ]; > > produces an error: > > Expected R_BRACKET; got TYPE at > [...]/lib/site_perl/5.28.1/Type/Parser.pm line 391. > > Changing the '-' in 'start-end' to any other character (well, any that > I've tried!) makes it behave.
On further investigation, I can't reproduce this on a clean install of Type::Tiny on a clean install of Perl. Still investigating...
On Sat Jun 01 22:12:45 2019, DJERIUS wrote: Show quoted text
> On Sat Jun 01 21:30:22 2019, DJERIUS wrote:
> > The following code > > > > use strict; > > use warnings; > > > > use Types::Standard qw[ Bool Enum ]; > > > > my $x = Bool | Enum [ 'start-end', 'end' ]; > > > > produces an error: > > > > Expected R_BRACKET; got TYPE at > > [...]/lib/site_perl/5.28.1/Type/Parser.pm line 391. > > > > Changing the '-' in 'start-end' to any other character (well, any > > that > > I've tried!) makes it behave.
> > > On further investigation, I can't reproduce this on a clean install of > Type::Tiny on a clean install of Perl. > > Still investigating...
The unexpected behavior requires Type::Tiny::XS to be installed. With it: % perl -d:Modlist -Ilocal/lib/perl5 opt.pl Expected R_BRACKET; got TYPE at local/lib/perl5/Type/Parser.pm line 391. B 1.74 Error::TypeTiny 1.004004 Eval::TypeTiny 1.004004 Exporter 5.73 Exporter::Tiny 1.002001 List::Util 1.5 Scalar::Util 1.5 Sub::Util 1.5 Type::Coercion 1.004004 Type::Library 1.004004 Type::Parser 1.004004 Type::Tiny 1.004004 Type::Tiny::Enum 1.004004 Type::Tiny::Union 1.004004 Type::Tiny::XS 0.014 Types::Standard 1.004004 Types::TypeTiny 1.004004 XSLoader 0.30 overload 1.30 overloading 0.02 re 0.36 warnings 1.42 warnings::register 1.04 Without it: % perl -d:Modlist -Ilocal/lib/perl5 opt.pl B 1.74 Eval::TypeTiny 1.004004 Exporter 5.73 Exporter::Tiny 1.002001 List::Util 1.5 Scalar::Util 1.5 Sub::Util 1.5 Type::Coercion 1.004004 Type::Coercion::Union 1.004004 Type::Library 1.004004 Type::Tiny 1.004004 Type::Tiny::Enum 1.004004 Type::Tiny::Union 1.004004 Types::Standard 1.004004 Types::TypeTiny 1.004004 XSLoader 0.30 overload 1.30 overloading 0.02 re 0.36 warnings 1.42 warnings::register 1.04
Yeah, Type::Tiny communicates with Type::Tiny::XS by stringifying the type constraint and parsing the string. This seems to be an error in Type::Parser, or an error stringifying it. Type::Tiny::Enum actually has a check to make sure none of the strings match /^-/ before attempting to use XS. Maybe if I generalize that to any hyphens (or maybe even any non-word characters), it will help.
PS: as a workaround, use StrMatch instead of Enum. Bool | StrMatch[qr/^(start-)?end$/]
On Sun Jun 02 04:22:19 2019, TOBYINK wrote: Show quoted text
> PS: as a workaround, use StrMatch instead of Enum. > > Bool | StrMatch[qr/^(start-)?end$/]
Thanks. That'll do it.
Fixed in repo.
Fixed in Type::Tiny 1.007_xxx.
On Sat Dec 07 11:56:56 2019, TOBYINK wrote: Show quoted text
> Fixed in Type::Tiny 1.007_xxx.
Thanks!