Skip Menu |

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

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

People
Owner: perl [...] toby.ink
Requestors: MMCLERIC [...] cpan.org
Cc:
AdminCc:

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



Subject: Optional constraints ignored if wrapped in Dict
See the test in attachment.
Subject: validation-test.pl
#!/usr/bin/env perl use strict; use warnings; use Test::More; use Test::Fatal; use Type::Params qw(validate compile); use Types::Standard qw(ArrayRef Dict Optional Str); sub f { validate(\@_, Optional[Str]); } is exception { f("foo") }, undef; is exception { f() }, undef; like exception { f(["abc"]) }, qr/type constraint/; sub g { validate(\@_, Dict[ foo => Optional[Str] ]); } is exception { g({ foo => "foo" }) }, undef; is exception { g({}) }, undef; like exception { g({ foo => ["abc"] }) }, qr/type constraint/; done_testing; =cut Test output: ok 1 ok 2 ok 3 ok 4 ok 5 Use of uninitialized value $this in pattern match (m//) at validation-test.pl line 27. not ok 6 # Failed test at validation-test.pl line 27. # undef # doesn't match '(?^:type constraint)' 1..6 # Looks like you failed 1 test of 6.
All bugs seem to be in Dict these days. (I don't use Dict myself very much which is probably why I haven't encountered them myself so much.)
This seems to be a coercion getting triggered: { foo => ["abc"] } -> {} Though I believe that it's the intention that Dict coercions should prefer to croak rather than drop hash keys.
Subject: Re: [rt.cpan.org #86239] Optional constraints ignored if wrapped in Dict
Date: Tue, 18 Jun 2013 23:56:34 +0400
To: "bug-Type-Tiny [...] rt.cpan.org" <bug-type-tiny [...] rt.cpan.org>
From: Vyacheslav Matyukhin <me [...] berekuk.ru>
Yes, if it's croaking on unknown keys, I don't see why it should ignore Optional keys with invalid value. 18.06.2013, 23:48, "Toby Inkster via RT" <bug-Type-Tiny@rt.cpan.org>: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=86239 > > > This seems to be a coercion getting triggered: > >    { foo => ["abc"] }    ->    {} > > Though I believe that it's the intention that Dict coercions should prefer to croak rather than drop hash keys.
Fix is in 0.007_09 developer version.
Fixed in 0.008.