docs: add documentation about return stm in the defer method

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
Vincenzo Palazzo 2022-05-17 18:34:28 +02:00
parent f3517a1aa6
commit 8328f5ed51
No known key found for this signature in database
GPG key ID: 8B6DC2B870B80D5F

View file

@ -4813,6 +4813,19 @@ fn deferErrorExample(is_error: bool) !void {
print("encountered an error!\n", .{});
}
// inside a defer method the return statement
// is not allowed.
// The following lines produce the following
// error if uncomment
// ```
// defer.zig:73:9: error: cannot return from defer expression
// return error.DeferError;
// ```
//
//defer {
// return error.DeferError;
//}
if (is_error) {
return error.DeferError;
}