diff options
| author | Loris Cro <kappaloris@gmail.com> | 2023-01-03 18:19:21 +0100 |
|---|---|---|
| committer | Loris Cro <kappaloris@gmail.com> | 2023-01-03 18:20:06 +0100 |
| commit | 755f50a986f429f7395848e883e154c3ab6c3f26 (patch) | |
| tree | 0e89b157b00a088919d08d2ea25b6a2fe6ef46bf /src | |
| parent | abd005f302ee81213b3f3a97a08d025cb3b1ecee (diff) | |
| download | zig-755f50a986f429f7395848e883e154c3ab6c3f26.tar.gz zig-755f50a986f429f7395848e883e154c3ab6c3f26.zip | |
autodoc: restore generic function functionality
latest changes to zir encoding broke simple return type detection
Diffstat (limited to 'src')
| -rw-r--r-- | src/Autodoc.zig | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/Autodoc.zig b/src/Autodoc.zig index 7664d6cdbf..6f7e15c4f6 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -3798,7 +3798,7 @@ fn analyzeFancyFunction( file, scope, parent_src, - fn_info.body[fn_info.body.len - 1], + fn_info.body[0], ); } else { break :blk null; @@ -3936,7 +3936,7 @@ fn analyzeFunction( file, scope, parent_src, - fn_info.body[fn_info.body.len - 1], + fn_info.body[0], ); } else { break :blk null; @@ -3977,11 +3977,25 @@ fn getGenericReturnType( file: *File, scope: *Scope, parent_src: SrcLocInfo, // function decl line - body_end: usize, + body_main_block: usize, ) !DocData.Expr { - // TODO: compute the correct line offset - const wr = try self.walkInstruction(file, scope, parent_src, body_end - 3, false); - return wr.expr; + const tags = file.zir.instructions.items(.tag); + const data = file.zir.instructions.items(.data); + + // We expect `body_main_block` to be the first instruction + // inside the function body, and for it to be a block instruction. + const pl_node = data[body_main_block].pl_node; + const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); + const maybe_ret_node = file.zir.extra[extra.end..][extra.data.body_len - 4]; + switch (tags[maybe_ret_node]) { + .ret_node, .ret_load => { + const wr = try self.walkInstruction(file, scope, parent_src, maybe_ret_node, false); + return wr.expr; + }, + else => { + return DocData.Expr{ .comptimeExpr = 0 }; + }, + } } fn collectUnionFieldInfo( |
