File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -12,26 +12,26 @@ context.
12
12
C < Nil > , when assigned, evaporates into the type object of the type of the
13
13
container you assigned it into.
14
14
15
- my Int $x = 42;
16
- $x = Nil;
17
- $x.say; # (Int)
15
+ my Int $x = 42;
16
+ $x = Nil;
17
+ $x.say; # (Int)
18
18
19
19
It is for this reason that assigning an untyped container as C < Nil > will result
20
20
in an C < (Any) > object.
21
21
22
- my $x = Nil;
23
- $x.say; # (Any)
24
- my Int $y = $x; # error: Type check failed in assignment to '$y'; expected 'Int' but got 'Any'
22
+ my $x = Nil;
23
+ $x.say; # (Any)
24
+ my Int $y = $x; # error: Type check failed in assignment to '$y'; expected 'Int' but got 'Any'
25
25
26
26
This is because an untyped container is C < Any > until proven otherwise, and
27
27
the C < Nil > evaporates.
28
28
29
29
If you are looking for a variable which transforms objects into type objects
30
30
when said variable appears on the RHS, you can type the container as C < Nil > .
31
31
32
- my Nil $x;
33
- my Str $s = $x;
34
- $s.say; # (Str)
32
+ my Nil $x;
33
+ my Str $s = $x;
34
+ $s.say; # (Str)
35
35
36
36
= head1 Methods
37
37
@@ -48,3 +48,5 @@ Returns C<"Nil">.
48
48
Returns the empty string.
49
49
50
50
= end pod
51
+
52
+ # vim: expandtab shiftwidth=4 ft=perl6
You can’t perform that action at this time.
0 commit comments