File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 9
9
Represents an empty list in list context, and an undefined value in item
10
10
context.
11
11
12
+ C < Nil > , when assigned, evaporates into the type object of the type of the
13
+ container you assigned it into.
14
+
15
+ my Int $x = 42;
16
+ $x = Nil;
17
+ $x.say; # (Int)
18
+
19
+ It is for this reason that assigning an untyped container as C < Nil > will result
20
+ in an C < (Any) > object.
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'
25
+
26
+ This is because an untyped container is C < Any > until proven otherwise, and
27
+ the C < Nil > evaporates
28
+
29
+ If you are looking for a variable which transforms objects into type objects
30
+ when said variable appears on the RHS, you can type the container as C < Nil > .
31
+
32
+ my Nil $x;
33
+ my Str $s = $x;
34
+ $s.say; # (Str)
12
35
13
36
= head1 Methods
14
37
You can’t perform that action at this time.
0 commit comments