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
#!/usr/bin/perl -wuse strict;
use Type::Params qw(compile);
use Types::Standard qw(Dict Int);
formy$sub (
sub {
my$check = compile(Dict[key=> Int]);
$check->({ key=>'f' });
},
sub {
compile(Dict[key=> Int])->({ key=>'f' });
},
sub {
my$check = compile(Dict[key=> Int]);
$check->({ key=>'f' });
},
) {
print"\n", "#"x80, "\n";
eval { $sub->() };
print$@;
}
Produces this output:
################################################################################
Reference {"key" => "f"} did not pass type constraint "Dict[key=>Int]" (in $_[0]) at /home/peter/junk/explainMissing.pl line 20
################################################################################
Reference {"key" => "f"} did not pass type constraint "Dict[key=>Int]" (in $_[0]) at /home/peter/junk/explainMissing.pl line 20
Reference {"key" => "f"} did not pass type constraint "Dict[key=>Int]" (in $_[0])
"Dict[key=>Int]" constrains value at key "key" of hash with "Int"
"Int" is a subtype of "Num"
"Num" is a subtype of "LaxNum"
Value "f" did not pass type constraint "LaxNum" (in $_[0]->{"key"})
"LaxNum" is defined as: (defined($_) && !ref($_) && Scalar::Util::looks_like_number($_))
################################################################################
Reference {"key" => "f"} did not pass type constraint "Dict[key=>Int]" (in $_[0]) at /home/peter/junk/explainMissing.pl line 20
Reference {"key" => "f"} did not pass type constraint "Dict[key=>Int]" (in $_[0])
"Dict[key=>Int]" constrains value at key "key" of hash with "Int"
"Int" is a subtype of "Num"
"Num" is a subtype of "LaxNum"
Value "f" did not pass type constraint "LaxNum" (in $_[0]->{"key"})
"LaxNum" is defined as: (defined($_) && !ref($_) && Scalar::Util::looks_like_number($_))
I would have expected all these tree subs to produce the same $@ - but they don't. In addition, the first sub (without the explanation) is missing a newline. That has been fixed in pull-request #33.
The text was updated successfully, but these errors were encountered:
This code:
Produces this output:
I would have expected all these tree subs to produce the same
$@
- but they don't. In addition, the first sub (without the explanation) is missing a newline. That has been fixed in pull-request #33.The text was updated successfully, but these errors were encountered: