File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,31 @@ say limit-lines "a \n b \n c", Int; # "a \n b \n c"
149
149
For explicitly indicating the normal behaviour, C < :_ > can be used, but this is
150
150
unnecessary. C < :(Num:_ $) > is the same as C < :(Num $) > .
151
151
152
+ = head3 X « Constraining Return Types|-->;returns »
153
+
154
+ The token C < -- > > followed by a type will force a type check on successful
155
+ execution of a routine. The return type arrow has to be placed at the end of
156
+ the parameter list. The keyword C < returns > following a signature declaration
157
+ has the same function. C < Nil > is considered as being defined for the type check.
158
+
159
+
160
+ sub foo(--> Int) { 1 };
161
+ sub foo() returns Int { 1 };
162
+ sub does-not-work(--> Int) { "" }; # throws X::TypeCheck::Return
163
+
164
+ If the type constrain is a constant expression, it is used as the return value
165
+ of the routine. Any return statement in that routine has to be argumentless.
166
+
167
+ sub foo(--> 123) { return }
168
+
169
+ C < Nil > and C < Failure > are always allowed as return types, reguardless of any
170
+ type contrain.
171
+
172
+ sub foo(--> Int) { Nil };
173
+ say foo.perl; # Nil
174
+
175
+ Type captures and coercion types are not supported.
176
+
152
177
= head2 X < Slurpy (A.K.A. Variadic) Parameters|parameter,*@;parameter,*% >
153
178
154
179
An array or hash parameter can be marked as I < slurpy > by leading asterisk(s),
You can’t perform that action at this time.
0 commit comments