Skip to content

Commit 0f2dcd3

Browse files
author
Jan-Olof Hendig
committed
Fixed some issues, mostly relating to code example output
1 parent bc2470c commit 0f2dcd3

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

doc/Type/Signature.pod6

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ closure.
4949
5050
f(&won't-work);
5151
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'␤»
5353
5454
f(-> Int { 'this works too' } );
5555
@@ -188,7 +188,7 @@ can be used to that effect.
188188
f(42);
189189
f(<a>);
190190
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' ...»
192192
193193
=head3 Constraining named Arguments
194194
@@ -198,7 +198,7 @@ part of the L<colon-pair|/type/Pair>.
198198
sub f(Int :$i){};
199199
f :i<forty-two>;
200200
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")␤»
202202
203203
=head3 X<Constraining Defined and Undefined Values|
204204
type constraint,:D;type constraint,:U;type constraint,:_>
@@ -210,11 +210,10 @@ correct type.
210210
my @lines = $s.lines;
211211
@lines[0 .. min @lines.elems, $limit].join("\n")
212212
}
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 "
214214
say limit-lines Str, 3;
215215
CATCH { default { put .^name, ': ', .Str } };
216216
# OUTPUT: «X::Multi::NoMatch: Cannot resolve caller lines(Str: ); none of these signatures match:
217-
# (Cool:D $: |c is raw)
218217
# (Str:D $: :$count!, *%_)
219218
# (Str:D $: $limit, *%_)
220219
# (Str:D $: *%_)»
@@ -226,8 +225,8 @@ use the C<:D> type constraint.
226225
sub limit-lines(Str:D $s, Int $limit) { };
227226
say limit-lines Str, 3;
228227
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'
231230
232231
This is much better than the way the program failed before, since here the
233232
reason for failure is clearer.
@@ -267,7 +266,7 @@ and passed on down the call chain.
267266
sub foo(--> Int) { Nil };
268267
say foo.perl; # OUTPUT: «Nil␤»
269268
270-
Type captures and coercion types are not supported.
269+
Type captures are not supported.
271270
272271
=item C<-->>
273272
@@ -327,7 +326,7 @@ C<of> is just the real name of the C<returns> keyword.
327326
=item prefix(C-like) form
328327
329328
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.
331330
332331
=begin code :skip-test
333332
my Int sub bar { 1 }; # Valid
@@ -348,7 +347,7 @@ be omitted.
348347
augment class Str { method Date() { Date.new(self) } };
349348
sub foo(Date(Str) $d) { say $d.WHAT; say $d };
350349
foo "2016-12-01";
351-
# OUTPUT: «Date.new(2016,11,1)␤»
350+
# OUTPUT: «(Date)␤2016-12-01␤»
352351
353352
=head2 X<Slurpy (A.K.A. Variadic) Parameters|parameter,*@;parameter,*%,slurpy argument (Signature)>
354353
@@ -525,17 +524,17 @@ L<Pair|/type/Pair> with C<|> to turn it into a named argument.
525524
multi f(:$named) { note &?ROUTINE.signature };
526525
multi f(:$also-named) { note &?ROUTINE.signature };
527526
for 'named', 'also-named' -> $n {
528-
f(|($n => rand)) # RESULT: «(:$named)␤(:$also-named)␤»
527+
f(|($n => rand)) # OUTPUT: «(:$named)␤(:$also-named)␤»
529528
}
530529
531530
my $pair = :named(1);
532-
f |$pair; # RESULT: «(:$named)␤»
531+
f |$pair; # OUTPUT: «(:$named)␤»
533532
534533
The same can be used to convert a C<Hash> into named arguments.
535534
536535
sub f(:$also-named) { note &?ROUTINE.signature };
537536
my %pairs = also-named => 4;
538-
f |%pairs; # «(:$also-named)␤»
537+
f |%pairs; # OUTPUT: «(:$also-named)␤»
539538
540539
A C<Hash> that contains a list may prove problematic when slipped into named
541540
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.
711710
712711
Whatever the Signature's return constraint is:
713712
714-
:($a, $b --> Int).returns # RESULT: «Int»
713+
:($a, $b --> Int).returns # RESULT: «(Int)»
715714
716715
=head2 method ACCEPTS
717716

0 commit comments

Comments
 (0)