Skip to content

Commit a1f57b8

Browse files
committed
Rework Parameter.type_captures example
1 parent 664ebbb commit a1f57b8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

doc/Type/Parameter.pod6

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,18 @@ The type used may change from call to call. Once they are defined,
326326
type captures can be used wherever you would use a type, even later
327327
in the same signature:
328328
329-
=for code
329+
=begin code
330330
sub c(::T $x, T $y, $z) { my T $zz = $z };
331331
c(4, 5, 6); # OK
332-
c(4, 5, "six"); # Fails when assigning to $zz, wants Int not Str
333-
c("four", 5, "six"); # Fails when binding $y, wants Str, not Int
332+
333+
try c(4, 5, "six");
334+
given $! { .message.say };
335+
# OUTPUT: «Type check failed in assignment to $zz; expected Int but got Str ("six")␤»
336+
337+
try c("four", 5, "six");
338+
given $! { .message.say };
339+
# OUTPUT: «Type check failed in binding to parameter '$y'; expected Str but got Int (5)␤»
340+
=end code
334341
335342
Type captures may be used at the same time as
336343
L<type constraints|/type/Signature#Type_constraints>.

0 commit comments

Comments
 (0)