@@ -169,6 +169,7 @@ can be used to that effect.
169
169
sub f(*@a where {$_.all ~~ Int}) { say @a };
170
170
f(42);
171
171
f(<a>);
172
+ CATCH { default { say .^name, ' ==> ', .Str } }
172
173
# OUTPUT « [42]Constraint type check failed for parameter '@a' in sub f at ... »
173
174
174
175
= head3 Constraining named Arguments
@@ -245,9 +246,9 @@ has the same function. C<Nil> and its subclasses do B<not> abide by return
245
246
constraints. This allows L < Failure|/type/Failure > to be returned and passed on
246
247
down the call chain.
247
248
248
- sub(--> Int) { my Int $i; $i };
249
- sub(--> Int:D) { 1 }
250
- sub() returns Int { 1 };
249
+ sub foo (--> Int) { my Int $i; $i };
250
+ sub baz (--> Int:D) { 1 }
251
+ sub bar () returns Int { 1 };
251
252
sub does-not-work(--> Int) { "" }; # throws X::TypeCheck::Return
252
253
253
254
If the type constraint is a constant expression, it is used as the return value
@@ -345,7 +346,7 @@ dissolving one or more layers of bare C<Iterables>.
345
346
my @array = <a b c>;
346
347
my $list := <d e f>;
347
348
sub a(*@a) { @a.perl.say };
348
- a(@array) # ["a", "b", "c"]
349
+ a(@array); # ["a", "b", "c"]
349
350
a(1, $list, [2, 3]); # [1, "d", "e", "f", 2, 3]
350
351
a([1, 2]); # [1, 2]
351
352
a(1, [1, 2], ([3, 4], 5)); # [1, 1, 2, 3, 4 5]
0 commit comments