aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-05-08 13:46:48 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-05-08 13:48:40 -0700
commitb98a753b52ce293e97d0f708b077702cf7024ac4 (patch)
tree7e8ae41926eeec0482aa0ca51d81ea1640133133 /src
parent3d351c91d841555b7baeb0e95cf9b98f596bdc71 (diff)
downloadzig-b98a753b52ce293e97d0f708b077702cf7024ac4.tar.gz
zig-b98a753b52ce293e97d0f708b077702cf7024ac4.zip
AstGen: fix incorrect logic for adding implicit return instruction
Diffstat (limited to 'src')
-rw-r--r--src/AstGen.zig11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 32220948a3..7d52fd9cf4 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -2864,9 +2864,14 @@ fn fnDecl(
_ = try expr(&fn_gz, params_scope, .none, body_node);
}
- if (fn_gz.instructions.items.len == 0 or
- !astgen.instructions.items(.tag)[fn_gz.instructions.items.len - 1].isNoReturn())
- {
+ const need_implicit_ret = blk: {
+ if (fn_gz.instructions.items.len == 0)
+ break :blk true;
+ const last = fn_gz.instructions.items[fn_gz.instructions.items.len - 1];
+ const zir_tags = astgen.instructions.items(.tag);
+ break :blk !zir_tags[last].isNoReturn();
+ };
+ if (need_implicit_ret) {
// Since we are adding the return instruction here, we must handle the coercion.
// We do this by using the `ret_coerce` instruction.
_ = try fn_gz.addUnTok(.ret_coerce, .void_value, tree.lastToken(body_node));