authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-08 13:46:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-08 13:48:40-07:00
logb98a753b52ce293e97d0f708b077702cf7024ac4
tree7e8ae41926eeec0482aa0ca51d81ea1640133133
parent3d351c91d841555b7baeb0e95cf9b98f596bdc71

AstGen: fix incorrect logic for adding implicit return instruction


1 files changed, 8 insertions(+), 3 deletions(-)

src/AstGen.zig+8-3
...@@ -2864,9 +2864,14 @@ fn fnDecl(...@@ -2864,9 +2864,14 @@ fn fnDecl(
2864 _ = try expr(&fn_gz, params_scope, .none, body_node);2864 _ = try expr(&fn_gz, params_scope, .none, body_node);
2865 }2865 }
28662866
2867 if (fn_gz.instructions.items.len == 0 or2867 const need_implicit_ret = blk: {
2868 !astgen.instructions.items(.tag)[fn_gz.instructions.items.len - 1].isNoReturn())2868 if (fn_gz.instructions.items.len == 0)
2869 {2869 break :blk true;
2870 const last = fn_gz.instructions.items[fn_gz.instructions.items.len - 1];
2871 const zir_tags = astgen.instructions.items(.tag);
2872 break :blk !zir_tags[last].isNoReturn();
2873 };
2874 if (need_implicit_ret) {
2870 // Since we are adding the return instruction here, we must handle the coercion.2875 // Since we are adding the return instruction here, we must handle the coercion.
2871 // We do this by using the `ret_coerce` instruction.2876 // We do this by using the `ret_coerce` instruction.
2872 _ = try fn_gz.addUnTok(.ret_coerce, .void_value, tree.lastToken(body_node));2877 _ = try fn_gz.addUnTok(.ret_coerce, .void_value, tree.lastToken(body_node));