Skip to content

Commit 8bd9ff0

Browse files
committed
doc new behaviour of Nil and add Nilness of subclasses of Nil
1 parent 7fd6934 commit 8bd9ff0

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

doc/Type/Nil.pod6

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@
77
class Nil is Cool { }
88
99
The value C<Nil> may be used to fill a spot where a value would normally
10-
go, and in so doing, explicitly indicate that no value is present. It
10+
go, and in so doing, explicitly indicate that no value is present. It
1111
may also used as a cheaper and less explosive alternative to a
1212
L<C<Failure>|/type/Failure>.
1313
1414
The class C<Nil> is the same exact thing as its only possible value, C<Nil>.
1515
1616
say Nil === Nil.new #-> True
1717
18-
Along with C<Failure>, C<Nil> is one of the two types which may
19-
always be returned from a routine even when the routine specifies a
20-
particular return type. It may also be returned regardless of the
21-
definedness of the return type, however, C<Nil> is considered undefined
22-
for all other purposes.
18+
Along with C<Failure>, C<Nil> and its sub classes may always be returned from a
19+
routine even when the routine specifies a particular return type. It may also
20+
be returned regardless of the definedness of the return type, however, C<Nil>
21+
is considered undefined for all other purposes.
2322
2423
sub a( --> Int:D ) { return Nil }
2524
a().say; #-> Nil
@@ -48,21 +47,16 @@ C<Nil>.
4847
say (Nil)[100]; #-> Nil
4948
say (Nil){100}; #-> Nil
5049
51-
When assigned, C<Nil> will revert a container to its default value, if no such
52-
default is provided Perl 6 assumes C<Any>. This includes initializers on
53-
defined constrained types. Returning C<Nil> from a routine will break the
54-
definedness constraint. Subsequent assignments to another definedness
55-
constraint container, including L<Signature|/type/Signature>s, will properly
56-
fail.
50+
When assigned, C<Nil> and any subclass of C<Nil> will revert a container to its
51+
default value, if no such default is provided Perl 6 assumes C<Any>. Assigning
52+
to a defined constrained container will produce a L<Failure|/type/Failure>.
5753
5854
my Int $x = 42;
5955
$x = Nil;
6056
$x.say; #-> (Int)
6157
62-
sub f(-->Int:D){Nil};
63-
my Int:D $i = f;
64-
say $i.defined;
65-
# OUTPUT«False␤»
58+
sub f( -->Int:D ){ Nil }; # this definedness constraint is ignored
59+
my Int:D $i = f; # this definedness contraint is not ignored
6660
6761
Because an untyped variable is type C<Any>, assigning a C<Nil> to one
6862
will result in an L<(Any)|/type/Any> type object.

doc/Type/Signature.pod6

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,9 @@ the signature after the argument name.
196196
The token C<-->> followed by a type will force a type check on successful
197197
execution of a routine. The return type arrow has to be placed at the end of
198198
the parameter list. The keyword C<returns> following a signature declaration
199-
has the same function. C<Nil> is considered as being defined for the type
200-
check. Type objects and thus undefined values will pass the test unless the
201-
type smiley C<:D> is used.
202-
199+
has the same function. C<Nil> and its subclasses are ignored in return
200+
constraints. This allowes L<Failure|/type/Failure> to be returned and passed on
201+
down the call chain.
203202
204203
sub foo(--> Int) { my Int $i; $i };
205204
sub foo(--> Int:D) { 1 }

0 commit comments

Comments
 (0)