You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#! perl
use strict;
use warnings;
package My::Types {
use Type::Library -base;
__PACKAGE__->meta->add_type(
Type::Tiny->new(
name => 'Sexagesimal',
constraint_generator => sub {
return Type::Tiny->new(
constraint => sub { 0 },
parameters => [@_],
);
},
constraint => sub {
croak( 'Sexagesimal requires parameters' );
},
),
);
}
My::Types::Sexagesimal()->of()->assert_valid( 0 );
This results in:
Can't call method "has_deep_explanation" on an undefined value at .../Type/Tiny.pm line 917.
That's in Type::Tiny::valid_explain, which doesn't check that the type has a parent before calling has_deep_explanation on the parent:
917 if ( $self->is_parameterized and $self->parent->has_deep_explanation ) {
918 my $deep = $self->parent->deep_explanation->( $self, $value, $varname );
919 return [ $message, @$deep ] if $deep;
920 }
Why would I create a parentless parameterized type? I want the Sexagesimal type to croak if it is used as a non-parameterized type, so I have the non-parameterized constraintcroak if called.
However, if the parameterized type inherits from Sexagesimal, it will call Sexagesimal's non-parameterized constraint which will croak. To avoid that, the parameterized type doesn't have a parent. (I've since set its parent to Any as a workaround.)
The text was updated successfully, but these errors were encountered:
It's an assumption that the unparameterized type will always be the parent of a parameterized type, even though I don't think I've documented that or enforced it anywhere.
In your case, is there even really a need for a Sexagesimal type constraint at all? You could just create a sub:
Here's a parentless parameterized type:
This results in:
That's in Type::Tiny::valid_explain, which doesn't check that the type has a parent before calling
has_deep_explanation
on the parent:Why would I create a parentless parameterized type? I want the
Sexagesimal
type to croak if it is used as a non-parameterized type, so I have the non-parameterizedconstraint
croak
if called.However, if the parameterized type inherits from
Sexagesimal
, it will callSexagesimal
's non-parameterized constraint which willcroak
. To avoid that, the parameterized type doesn't have a parent. (I've since set its parent toAny
as a workaround.)The text was updated successfully, but these errors were encountered: