Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes "explain" is missing from Error::TypeTiny::Assertion #34

Closed
pmorch opened this issue Jun 10, 2016 · 1 comment
Closed

Sometimes "explain" is missing from Error::TypeTiny::Assertion #34

pmorch opened this issue Jun 10, 2016 · 1 comment

Comments

@pmorch
Copy link
Contributor

pmorch commented Jun 10, 2016

This code:

#!/usr/bin/perl -w
use strict;
use Type::Params qw(compile);
use Types::Standard qw(Dict Int);

for my $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", "#" x 80, "\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.

@tobyink
Copy link
Owner

tobyink commented May 18, 2017

@tobyink tobyink closed this as completed May 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants