File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -178,20 +178,23 @@ values.
178
178
179
179
Perl 6 has many ways to specify a function's return type:
180
180
181
- sub foo(--> Int) {}; say &foo.returns # (Int)
182
- sub foo() returns Int {}; say &foo.returns # (Int)
183
- sub foo() of Int {}; say &foo.returns # (Int)
184
- my Int sub foo() {}; say &foo.returns # (Int)
181
+ = for code :skip-test
182
+ sub foo(--> Int) {}; say &foo.returns; # (Int)
183
+ sub foo() returns Int {}; say &foo.returns; # (Int)
184
+ sub foo() of Int {}; say &foo.returns; # (Int)
185
+ my Int sub foo() {}; say &foo.returns; # (Int)
185
186
186
187
Attempting to return values of another type will cause a compilation error.
187
188
188
- sub foo() returns Int { "a"; }; foo; # Type check fails
189
+ = for code :catch-all
190
+ sub foo() returns Int { "a"; }; foo; # Type check fails
189
191
190
192
Note that C < Nil > and C < Failure > are excempt from return type constraints and
191
193
can be returned from any routine, regardless of its constraint:
192
194
193
- sub foo() returns Int { fail }; foo; # Failure returned
194
- sub foo() returns Int { return }; foo; # Nil returned
195
+ = for code :catch-all
196
+ sub foo() returns Int { fail }; foo; # Failure returned
197
+ sub bar() returns Int { return }; bar; # Nil returned
195
198
196
199
= head2 X < Multi-dispatch|declarator,multi >
197
200
You can’t perform that action at this time.
0 commit comments