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
Constraint Checked On Missing Named Parameters #4987
Comments
From @zoffixznetIf a constraint is created on a named parameter with either with a `where` or with a `subset` and that named parameter is NOT present in the call of the subrouting, the constraint check still occurs. This makes it impossible to have optional constrained named parameters. Here's the output showing (1) successfull use of optional named parameter without constraint; (2) error with `subset` constraint. (3) error with `where` constraint: <Zoffix> m: sub foo (Int :$x){}; foo Relevant IRC conversation: http://irclog.perlgeek.de/perl6/2016-01-03#i_11823741 |
From @zoffixznet
There is a way, but it's ugly, unintuitive, and differs from what is needed when the parameter is non-optional. <Zoffix> m: sub foo(:$x where { !$_.defined || $_ < 42 }) {}; foo Also, the issue exists with optional positional parameters as well: |
From @zoffixznet
Errr, (no edit button), the way shown above is not really a solution as it misses when the argument IS specified, but not defined. |
Migrated from rt.perl.org#127142 (status was 'new')
Searchable as RT127142$
The text was updated successfully, but these errors were encountered: