Skip to content

Commit e01ec96

Browse files
committed
Autodoc: not all block_inlines contain a break_inline
1 parent 52b8efc commit e01ec96

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/AstGen.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7940,7 +7940,9 @@ fn builtinCall(
79407940
},
79417941

79427942
.src => {
7943-
maybeAdvanceSourceCursorToMainToken(gz, node);
7943+
const token_starts = tree.tokens.items(.start);
7944+
const node_start = token_starts[tree.firstToken(node)];
7945+
astgen.advanceSourceCursor(node_start);
79447946
const result = try gz.addExtendedPayload(.builtin_src, Zir.Inst.Src{
79457947
.node = gz.nodeIndexToRelative(node),
79467948
.line = astgen.source_line,

src/Autodoc.zig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,15 @@ fn walkInstruction(
21292129
file,
21302130
parent_scope,
21312131
parent_src,
2132-
getBlockInlineBreak(file.zir, inst_index),
2132+
getBlockInlineBreak(file.zir, inst_index) orelse {
2133+
const res = DocData.WalkResult{ .expr = .{
2134+
.comptimeExpr = self.comptime_exprs.items.len,
2135+
} };
2136+
try self.comptime_exprs.append(self.arena, .{
2137+
.code = "if (...) { ... }",
2138+
});
2139+
return res;
2140+
},
21332141
need_type,
21342142
);
21352143
},
@@ -3155,7 +3163,7 @@ fn walkDecls(
31553163
2 => {
31563164
// decl test
31573165
const decl_being_tested = scope.resolveDeclName(doc_comment_index);
3158-
const func_index = getBlockInlineBreak(file.zir, value_index);
3166+
const func_index = getBlockInlineBreak(file.zir, value_index).?;
31593167

31603168
const pl_node = data[Zir.refToIndex(func_index).?].pl_node;
31613169
const fn_src = try self.srcLocInfo(file, pl_node.src_node, decl_src);
@@ -4301,12 +4309,13 @@ fn walkRef(
43014309
}
43024310
}
43034311

4304-
fn getBlockInlineBreak(zir: Zir, inst_index: usize) Zir.Inst.Ref {
4312+
fn getBlockInlineBreak(zir: Zir, inst_index: usize) ?Zir.Inst.Ref {
43054313
const tags = zir.instructions.items(.tag);
43064314
const data = zir.instructions.items(.data);
43074315
const pl_node = data[inst_index].pl_node;
43084316
const extra = zir.extraData(Zir.Inst.Block, pl_node.payload_index);
43094317
const break_index = zir.extra[extra.end..][extra.data.body_len - 1];
4318+
if (tags[break_index] == .condbr_inline) return null;
43104319
std.debug.assert(tags[break_index] == .break_inline);
43114320
return data[break_index].@"break".operand;
43124321
}

0 commit comments

Comments
 (0)