stage2: fix crash on file-level struct field source locations

This commit is contained in:
Andrew Kelley 2022-01-26 15:43:24 -07:00
parent b463924da2
commit 50accb757f
3 changed files with 15 additions and 10 deletions

View File

@ -1642,6 +1642,18 @@ pub fn containerDeclArg(tree: Ast, node: Node.Index) full.ContainerDecl {
});
}
pub fn containerDeclRoot(tree: Ast) full.ContainerDecl {
return .{
.layout_token = null,
.ast = .{
.main_token = undefined,
.enum_token = null,
.members = tree.rootDecls(),
.arg = 0,
},
};
}
pub fn taggedUnionTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) full.ContainerDecl {
assert(tree.nodes.items(.tag)[node] == .tagged_union_two or
tree.nodes.items(.tag)[node] == .tagged_union_two_trailing);

View File

@ -131,20 +131,11 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
};
defer gz_instructions.deinit(gpa);
const container_decl: Ast.full.ContainerDecl = .{
.layout_token = null,
.ast = .{
.main_token = undefined,
.enum_token = null,
.members = tree.rootDecls(),
.arg = 0,
},
};
if (AstGen.structDeclInner(
&gen_scope,
&gen_scope.base,
0,
container_decl,
tree.containerDeclRoot(),
.Auto,
)) |struct_decl_ref| {
assert(refToIndex(struct_decl_ref).? == 0);

View File

@ -935,6 +935,8 @@ pub const Struct = struct {
.tagged_union_enum_tag_trailing,
=> return queryFieldSrc(tree.*, query, file, tree.taggedUnionEnumTag(node)),
.root => return queryFieldSrc(tree.*, query, file, tree.containerDeclRoot()),
else => unreachable,
}
}