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

Optional accepts multiple parameters, only uses the first, but refers to all of them in error messages #156

Open
djerius opened this issue Jan 26, 2024 · 0 comments

Comments

@djerius
Copy link
Contributor

djerius commented Jan 26, 2024

More of a footgun then anything else, but if one mistakenly passes two parameters to Optional, the
resultant error message contains both, which can confuse the end user:

perl -MTypes::Standard=-all -e 'Optional([Str,CodeRef])->assert_valid(sub{})'
Reference sub { "DUMMY" } did not pass type constraint "Optional[Str,CodeRef]" at -e line 1
    Reference sub { "DUMMY" } did not pass type constraint "Optional[Str,CodeRef]"
    $_ exists
    "Optional[Str,CodeRef]" constrains $_ with "Str" if it exists
    "Str" is a subtype of "Value"
    Reference sub { "DUMMY" } did not pass type constraint "Value"
    "Value" is defined as: (defined($_) and not ref($_))
@djerius djerius changed the title Optional accepts multiple parameters, only uses the first, but refers to both in error messages Optional accepts multiple parameters, only uses the first, but refers to all of them in error messages Jan 26, 2024
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

1 participant