Subject: | I was bitten by equals() being looser than expected (ie structural) which impacts is_subtype_of() |
use Type::Library -base, -declare => qw(T1 T2);
use Types::Standard qw(Int);
use Type::Utils -all;
declare T1, as Int;
declare T2, as Int;
die "Oops!" if T1->is_subtype_of(T2);
Here T1 is clearly not a subtype of T2 yet Type::Tiny says it is: T1->is_subtype_of(T2); returns true!
Looking at the source, and the source of Moose::Meta::TypeConstraint, it seems that Type::Tiny and Moose implement equals() to mean something like "equivalent constraints".
This isn't made clear in the docs of either. I'd argue that is_subtype_of should use a stricter check but I've no idea what the backwards compatibility issues might be.
This is a problem when trying to use types for more than just constraint checking.