Skip to content

Commit 755f50a

Browse files
committed
autodoc: restore generic function functionality
latest changes to zir encoding broke simple return type detection
1 parent abd005f commit 755f50a

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

src/Autodoc.zig

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3798,7 +3798,7 @@ fn analyzeFancyFunction(
37983798
file,
37993799
scope,
38003800
parent_src,
3801-
fn_info.body[fn_info.body.len - 1],
3801+
fn_info.body[0],
38023802
);
38033803
} else {
38043804
break :blk null;
@@ -3936,7 +3936,7 @@ fn analyzeFunction(
39363936
file,
39373937
scope,
39383938
parent_src,
3939-
fn_info.body[fn_info.body.len - 1],
3939+
fn_info.body[0],
39403940
);
39413941
} else {
39423942
break :blk null;
@@ -3977,11 +3977,25 @@ fn getGenericReturnType(
39773977
file: *File,
39783978
scope: *Scope,
39793979
parent_src: SrcLocInfo, // function decl line
3980-
body_end: usize,
3980+
body_main_block: usize,
39813981
) !DocData.Expr {
3982-
// TODO: compute the correct line offset
3983-
const wr = try self.walkInstruction(file, scope, parent_src, body_end - 3, false);
3984-
return wr.expr;
3982+
const tags = file.zir.instructions.items(.tag);
3983+
const data = file.zir.instructions.items(.data);
3984+
3985+
// We expect `body_main_block` to be the first instruction
3986+
// inside the function body, and for it to be a block instruction.
3987+
const pl_node = data[body_main_block].pl_node;
3988+
const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index);
3989+
const maybe_ret_node = file.zir.extra[extra.end..][extra.data.body_len - 4];
3990+
switch (tags[maybe_ret_node]) {
3991+
.ret_node, .ret_load => {
3992+
const wr = try self.walkInstruction(file, scope, parent_src, maybe_ret_node, false);
3993+
return wr.expr;
3994+
},
3995+
else => {
3996+
return DocData.Expr{ .comptimeExpr = 0 };
3997+
},
3998+
}
39853999
}
39864000

39874001
fn collectUnionFieldInfo(

0 commit comments

Comments
 (0)