Skip Menu |

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

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

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

Bug Information
Severity: (no value)
Broken in:
  • 0.006
  • 0.007_02
Fixed in: (no value)



Subject: "coercion cannot be inlined" error w/ Type::Params::compile & Dict
The attached code when run under 5.16.3 results in the following error: $ perl type.pl [ [0] [ [0] "b" ] ] This coercion cannot be inlined at [...]/lib/perl5/Types/Standard.pm line 934. I'm not quite sure how to fix this...
Subject: type.pl
use strict; use warnings; package Types { use Type::Library -base, -declare => qw[ StrList ]; use Type::Utils; use Types::Standard qw[ ArrayRef Str ]; declare StrList, as ArrayRef [Str]; coerce StrList, from Str, via { [$_] }; } use Type::Params qw[ compile ]; use Types::Standard qw[ Dict slurpy Optional ]; sub foo { my $check = compile( Dict [ foo => Types::StrList ] ); my @opts = $check->( @_ ); use Data::Printer; p @opts; } sub bar { my $check = compile( Types::StrList ); my @opts = $check->( @_ ); use Data::Printer; p @opts; } bar( 'b' ); foo( foo => 'a' );
Hmmm... looks like I have some Type::Params test cases for non-inlineable type constraints, but not non-inlineable coercions. A workaround would be to express the coercion as a string instead of a coderef. Replacing `via {...}` with `q {...}` is usually sufficient. (Expressing coderefs as a string will result in faster runtime coercions too.) Thanks for the bug report. This will certainly need to be fixed for the next stable release.
On Thu Jun 06 15:38:16 2013, TOBYINK wrote: Show quoted text
> Hmmm... looks like I have some Type::Params test cases for non- > inlineable type constraints, but not non-inlineable coercions. > > A workaround would be to express the coercion as a string instead of a > coderef. Replacing `via {...}` with `q {...}` is usually sufficient. > > (Expressing coderefs as a string will result in faster runtime > coercions too.)
It's a bit unexpected that coercions are required to be inline-able. I didn't get that sense from the docs; is it possible to avoid that requirement? Thanks, Diab
On 2013-06-07T02:47:10+01:00, DJERIUS wrote: Show quoted text
> It's a bit unexpected that coercions are required to be inline-able.
They are not required to be inlineable (though inlineable ones are potentially faster). It is a bug that in this case non-inlineable coercions are failing.
On Fri Jun 07 08:44:02 2013, TOBYINK wrote: Show quoted text
> On 2013-06-07T02:47:10+01:00, DJERIUS wrote:
> > It's a bit unexpected that coercions are required to be inline-able.
> > They are not required to be inlineable (though inlineable ones are > potentially faster). It is a bug that in this case non-inlineable > coercions are failing.
Ok. I misunderstood your earlier statement.
Fixed in repo; also fixed a similar bug in the Tuple type. There may be similar lurking in Map, HashRef, ArrayRef and ScalarRef; I'll need to investigate these.
Type::Tiny 0.007_03 has just been uploaded, incorporating the fix for this issue. I'll close the ticket when I next do a stable release. I'm including a slightly modified version of your test script in the release - I hope that's OK. I've credited you as the author of the test case. https://metacpan.org/module/TOBYINK/Type-Tiny-0.007_03/t/rt85911.t
On Sat Jun 08 12:54:20 2013, TOBYINK wrote: Show quoted text
> Type::Tiny 0.007_03 has just been uploaded, incorporating the fix for > this issue. I'll close the ticket when I next do a stable release. > > I'm including a slightly modified version of your test script in the > release - I hope that's OK. I've credited you as the author of the > test case.
No problem. Glad to be of help.
Fixed in 0.008.