@@ -49,7 +49,7 @@ closure.
49
49
50
50
f(&won't-work);
51
51
CATCH { default { put .^name, ': ', .Str } };
52
- # OUTPUT: «X::AdHoc: Constraint type check failed for parameter '&c'»
52
+ # OUTPUT: «X::TypeCheck::Binding::Parameter: Constraint type check failed in binding to parameter '&c'»
53
53
54
54
f(-> Int { 'this works too' } );
55
55
@@ -188,7 +188,7 @@ can be used to that effect.
188
188
f(42);
189
189
f(<a>);
190
190
CATCH { default { say .^name, ' ==> ', .Str } }
191
- # OUTPUT: «[42]Constraint type check failed for parameter '@a' in sub f at ...»
191
+ # OUTPUT: «[42]Constraint type check failed in binding to parameter '@a' ...»
192
192
193
193
= head3 Constraining named Arguments
194
194
@@ -198,7 +198,7 @@ part of the L<colon-pair|/type/Pair>.
198
198
sub f(Int :$i){};
199
199
f :i<forty-two>;
200
200
CATCH { default { say .^name, ' ==> ', .Str } }
201
- # OUTPUT: «X::TypeCheck::Binding ==> Type check failed in binding to $i ; expected Int but got Str ("forty-two")»
201
+ # OUTPUT: «X::TypeCheck::Binding::Parameter ==> Type check failed in binding to parameter '$i' ; expected Int but got Str ("forty-two")»
202
202
203
203
= head3 X < Constraining Defined and Undefined Values|
204
204
type constraint,:D;type constraint,:U;type constraint,:_>
@@ -210,11 +210,10 @@ correct type.
210
210
my @lines = $s.lines;
211
211
@lines[0 .. min @lines.elems, $limit].join("\n")
212
212
}
213
- say (limit-lines "a \n b \n c \n d \n", 3).perl; # "a \n b \n c "
213
+ say (limit-lines "a \n b \n c \n d \n", 3).perl; # "a \n b \n c \n d "
214
214
say limit-lines Str, 3;
215
215
CATCH { default { put .^name, ': ', .Str } };
216
216
# OUTPUT: «X::Multi::NoMatch: Cannot resolve caller lines(Str: ); none of these signatures match:
217
- # (Cool:D $: |c is raw)
218
217
# (Str:D $: :$count!, *%_)
219
218
# (Str:D $: $limit, *%_)
220
219
# (Str:D $: *%_)»
@@ -226,8 +225,8 @@ use the C<:D> type constraint.
226
225
sub limit-lines(Str:D $s, Int $limit) { };
227
226
say limit-lines Str, 3;
228
227
CATCH { default { put .^name ~ '--' ~~ .Str } };
229
- # OUTPUT: «X::AdHoc-- Parameter '$s' requires an instance of type Str, but a
230
- # type object was passed . Did you forget a .new?»
228
+ # OUTPUT: «Parameter '$s' of routine 'limit-lines' must be an object instance of type ' Str',
229
+ # not a type object of type 'Str' . Did you forget a ' .new' ?»
231
230
232
231
This is much better than the way the program failed before, since here the
233
232
reason for failure is clearer.
@@ -267,7 +266,7 @@ and passed on down the call chain.
267
266
sub foo(--> Int) { Nil };
268
267
say foo.perl; # OUTPUT: «Nil»
269
268
270
- Type captures and coercion types are not supported.
269
+ Type captures are not supported.
271
270
272
271
= item C < -- > >
273
272
@@ -327,7 +326,7 @@ C<of> is just the real name of the C<returns> keyword.
327
326
= item prefix(C-like) form
328
327
329
328
This is similar to placing type constraints on variables like C < my Type $var = 20; > ,
330
- except the $var is a definition for a routine.
329
+ except the C < $var > is a definition for a routine.
331
330
332
331
= begin code :skip-test
333
332
my Int sub bar { 1 }; # Valid
@@ -348,7 +347,7 @@ be omitted.
348
347
augment class Str { method Date() { Date.new(self) } };
349
348
sub foo(Date(Str) $d) { say $d.WHAT; say $d };
350
349
foo "2016-12-01";
351
- # OUTPUT: «Date.new(2016,11,1) »
350
+ # OUTPUT: «(Date)2016-12-01 »
352
351
353
352
= head2 X < Slurpy (A.K.A. Variadic) Parameters|parameter,*@;parameter,*%,slurpy argument (Signature) >
354
353
@@ -525,17 +524,17 @@ L<Pair|/type/Pair> with C<|> to turn it into a named argument.
525
524
multi f(:$named) { note &?ROUTINE.signature };
526
525
multi f(:$also-named) { note &?ROUTINE.signature };
527
526
for 'named', 'also-named' -> $n {
528
- f(|($n => rand)) # RESULT : «(:$named)(:$also-named)»
527
+ f(|($n => rand)) # OUTPUT : «(:$named)(:$also-named)»
529
528
}
530
529
531
530
my $pair = :named(1);
532
- f |$pair; # RESULT : «(:$named)»
531
+ f |$pair; # OUTPUT : «(:$named)»
533
532
534
533
The same can be used to convert a C < Hash > into named arguments.
535
534
536
535
sub f(:$also-named) { note &?ROUTINE.signature };
537
536
my %pairs = also-named => 4;
538
- f |%pairs; # «(:$also-named)»
537
+ f |%pairs; # OUTPUT: «(:$also-named)»
539
538
540
539
A C < Hash > that contains a list may prove problematic when slipped into named
541
540
arguments. To avoid the extra layer of containers coerce to L < Map|/type/Map >
@@ -711,7 +710,7 @@ to the signature. Returns C<Inf> if there is a slurpy positional parameter.
711
710
712
711
Whatever the Signature's return constraint is:
713
712
714
- :($a, $b --> Int).returns # RESULT: «Int»
713
+ :($a, $b --> Int).returns # RESULT: «( Int) »
715
714
716
715
= head2 method ACCEPTS
717
716
0 commit comments