| ... | @@ -4813,6 +4813,19 @@ fn deferErrorExample(is_error: bool) !void { | ... | @@ -4813,6 +4813,19 @@ fn deferErrorExample(is_error: bool) !void { |
| 4813 | print("encountered an error!\n", .{}); | 4813 | print("encountered an error!\n", .{}); |
| 4814 | } | 4814 | } |
| 4815 | | 4815 | |
| | 4816 | // inside a defer method the return statement |
| | 4817 | // is not allowed. |
| | 4818 | // The following lines produce the following |
| | 4819 | // error if uncomment |
| | 4820 | // ``` |
| | 4821 | // defer.zig:73:9: error: cannot return from defer expression |
| | 4822 | // return error.DeferError; |
| | 4823 | // ``` |
| | 4824 | // |
| | 4825 | //defer { |
| | 4826 | // return error.DeferError; |
| | 4827 | //} |
| | 4828 | |
| 4816 | if (is_error) { | 4829 | if (is_error) { |
| 4817 | return error.DeferError; | 4830 | return error.DeferError; |
| 4818 | } | 4831 | } |