# New Ticket Created by  Zoffix Znet 
# Please include the string:  [perl #127142]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=127142 >


If 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
<camelia> rakudo-moar 3734ea: ( no output )
<Zoffix> m: subset Foo of Mu where $_ < 42; sub foo (Foo :$x){}; foo
<camelia> rakudo-moar 3734ea: OUTPUT«Cannot call infix:«<»(Mu, Int); none of 
these signatures match:␤    ($?)␤    (\a, \b)␤    (Real \a, Real \b)␤    (Int:D 
\a, Int:D \b)␤    (int $a, int $b)␤    (Num:D \a, Num:D \b --> Bool)␤    (num 
$a, num $b --> Bool)␤    (Rational:D \a,…»
<Zoffix> m: sub foo (:$x where Int){}; foo
<camelia> rakudo-moar 3734ea: OUTPUT«Constraint type check failed for parameter 
'$x'␤  in sub foo at /tmp/I02EogbpEg line 1␤  in block <unit> at 
/tmp/I02EogbpEg line 1␤␤»


Relevant IRC conversation: http://irclog.perlgeek.de/perl6/2016-01-03#i_11823741

Reply via email to