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

The message thrown should match the failed constraint #3

Open
autarch opened this issue Nov 6, 2016 · 1 comment
Open

The message thrown should match the failed constraint #3

autarch opened this issue Nov 6, 2016 · 1 comment

Comments

@autarch
Copy link
Member

autarch commented Nov 6, 2016

Migrated from rt.cpan.org #84351 (status was 'open')

Requestors:

From [email protected] (@autarch) on 2013-04-01 19:26:39:

When a type inherits from a series of parents, the failure message it throws should come from the failing parent if that parent's constraint fails.

This will require some changes to how inlining works. Maybe the inlined constraint needs to return false on success and return a failure message on failure?

@autarch
Copy link
Member Author

autarch commented Nov 6, 2016

From [email protected] (@tobyink) on 2013-05-16 23:52:43:

FYI, I initially had it working this way in Type::Tiny, but it made inlining stupidly complex so I switched to just throwing from the child type constraint.

But with the build up to 0.006 I'm working on an $exception->explain method which re-examines why the value failed the type constraint, step-by-step.

For example, checking [1,2,[3]] against ArrayRef[Int] gives an explanation like this:

[
  '[1,2,[3]] did not pass type constraint "ArrayRef[Int]"',
  '"Int" is a subtype of "Num"',
  '"Num" is a subtype of "Str"',
  '"Str" is a subtype of "Value"',
  '[3] did not pass type constraint "Value" (in $_->[2])',
  '"Value" is defined as: (defined($_) and not ref($_))',
],

This means that the extensive examination is avoided on "hot" code paths (i.e. where the value passes the type constraint), but can be explicitly called in, say, a catch block.

Anyway, that's just an idea of a different way this can be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant