Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add the return of default values when Nil is assigned
  • Loading branch information
ab5tract committed Jun 9, 2015
1 parent 2e7179a commit 48c0eb9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Type/Nil.pod
Expand Up @@ -17,7 +17,7 @@ container you assigned it into.
$x.say; #-> (Int)
It is for this reason that assigning an untyped container as C<Nil> will result
in an C<(Any)> object.
in an L<(Any)> object.
my $x = Nil;
$x.say; #-> (Any)
Expand All @@ -33,6 +33,14 @@ when said variable appears on the RHS, you can type the container as C<Nil>.
my Str $s = $x;
$s.say; #-> (Str)
There is an important exception to this transforms-into-type-object rule:
assigning C<Nil> to a variable which has a default will restore that default.
my Int $x is default(42) = -1;
my $y = 1;
for $x,$y -> $val is rw { $val = $reset unless $val > 0 }
$x.say; #-> 42
=head1 Methods
=head2 method gist
Expand Down

0 comments on commit 48c0eb9

Please sign in to comment.