Skip Menu |

This queue is for tickets about the Class-Slot CPAN distribution.

Report information
The Basics
Id: 125297
Status: resolved
Priority: 0/
Queue: Class-Slot

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

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



Subject: "$type" is not necessarily unique
For non-inlineable type constraints, you use: $Class::Slot::TYPE{$type}->check($value) However, there's no guarantee that "$type" will stringify to something unique. With Type::Tiny it's certainly possible to create, say, two different Type constraints which stringify to the same thing. For example: use Types::Standard qw( Int Str ); use Scalar::Util qw( refaddr ); my $type1 = Int->where("1"); my $type2 = Str->where("1"); # prove that they are different type constraints say $_->check("xyz") ? "pass" : "fail" for $type1, $type2; # but they stringify to the same thing. say for $type1, $type2; For other type implementations, it probably is too. Using refaddr($type) as your hash key might be slightly better. Not sure.
Thank you for the bug report and the tip. I think you are correct about refaddr likely being the best solution. I'll incorporate that and push an update shortly. On Wed May 09 15:40:54 2018, TOBYINK wrote: Show quoted text
> For non-inlineable type constraints, you use: > > $Class::Slot::TYPE{$type}->check($value) > > However, there's no guarantee that "$type" will stringify to something > unique. > > With Type::Tiny it's certainly possible to create, say, two different > Type constraints which stringify to the same thing. For example: > > use Types::Standard qw( Int Str ); > use Scalar::Util qw( refaddr ); > > my $type1 = Int->where("1"); > my $type2 = Str->where("1"); > > # prove that they are different type constraints > say $_->check("xyz") ? "pass" : "fail" for $type1, $type2; > > # but they stringify to the same thing. > say for $type1, $type2; > > For other type implementations, it probably is too. > > Using refaddr($type) as your hash key might be slightly better. Not > sure.
-- -Jeff Ober
This should now be fixed. I just pushed v0.02 to CPAN.