commit e01ec96288bd32c7ec3bba01ee200cc115cdfb1d (tree)
parent 52b8efc726097df70dca7287b0a8e16b0a8a642d
Author: Veikka Tuominen <git@vexu.eu>
Date: Wed, 9 Nov 2022 23:06:26 +0200
Autodoc: not all `block_inline`s contain a `break_inline`
Diffstat:
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/AstGen.zig b/src/AstGen.zig
@@ -7940,7 +7940,9 @@ fn builtinCall(
},
.src => {
- maybeAdvanceSourceCursorToMainToken(gz, node);
+ const token_starts = tree.tokens.items(.start);
+ const node_start = token_starts[tree.firstToken(node)];
+ astgen.advanceSourceCursor(node_start);
const result = try gz.addExtendedPayload(.builtin_src, Zir.Inst.Src{
.node = gz.nodeIndexToRelative(node),
.line = astgen.source_line,
diff --git a/src/Autodoc.zig b/src/Autodoc.zig
@@ -2129,7 +2129,15 @@ fn walkInstruction(
file,
parent_scope,
parent_src,
- getBlockInlineBreak(file.zir, inst_index),
+ getBlockInlineBreak(file.zir, inst_index) orelse {
+ const res = DocData.WalkResult{ .expr = .{
+ .comptimeExpr = self.comptime_exprs.items.len,
+ } };
+ try self.comptime_exprs.append(self.arena, .{
+ .code = "if (...) { ... }",
+ });
+ return res;
+ },
need_type,
);
},
@@ -3155,7 +3163,7 @@ fn walkDecls(
2 => {
// decl test
const decl_being_tested = scope.resolveDeclName(doc_comment_index);
- const func_index = getBlockInlineBreak(file.zir, value_index);
+ const func_index = getBlockInlineBreak(file.zir, value_index).?;
const pl_node = data[Zir.refToIndex(func_index).?].pl_node;
const fn_src = try self.srcLocInfo(file, pl_node.src_node, decl_src);
@@ -4301,12 +4309,13 @@ fn walkRef(
}
}
-fn getBlockInlineBreak(zir: Zir, inst_index: usize) Zir.Inst.Ref {
+fn getBlockInlineBreak(zir: Zir, inst_index: usize) ?Zir.Inst.Ref {
const tags = zir.instructions.items(.tag);
const data = zir.instructions.items(.data);
const pl_node = data[inst_index].pl_node;
const extra = zir.extraData(Zir.Inst.Block, pl_node.payload_index);
const break_index = zir.extra[extra.end..][extra.data.body_len - 1];
+ if (tags[break_index] == .condbr_inline) return null;
std.debug.assert(tags[break_index] == .break_inline);
return data[break_index].@"break".operand;
}