p5-type-tiny icon indicating copy to clipboard operation
p5-type-tiny copied to clipboard

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

Open djerius opened this issue 1 year ago • 0 comments

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 avatar Jan 26 '24 20:01 djerius