authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-26 15:43:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-26 20:02:01-07:00
log50accb757fb8514c3eac824fad5d09d569a6fdc9
treea14d6513f717343bf32fc2c96a81bde20b76c7cd
parentb463924da2b1ed4ae83a51c18b4998531c44d809

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


3 files changed, 15 insertions(+), 10 deletions(-)

lib/std/zig/Ast.zig+12
......@@ -1642,6 +1642,18 @@ pub fn containerDeclArg(tree: Ast, node: Node.Index) full.ContainerDecl {
16421642 });
16431643}
16441644
1645pub fn containerDeclRoot(tree: Ast) full.ContainerDecl {
1646 return .{
1647 .layout_token = null,
1648 .ast = .{
1649 .main_token = undefined,
1650 .enum_token = null,
1651 .members = tree.rootDecls(),
1652 .arg = 0,
1653 },
1654 };
1655}
1656
16451657pub fn taggedUnionTwo(tree: Ast, buffer: *[2]Node.Index, node: Node.Index) full.ContainerDecl {
16461658 assert(tree.nodes.items(.tag)[node] == .tagged_union_two or
16471659 tree.nodes.items(.tag)[node] == .tagged_union_two_trailing);
src/AstGen.zig+1-10
......@@ -131,20 +131,11 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
131131 };
132132 defer gz_instructions.deinit(gpa);
133133
134 const container_decl: Ast.full.ContainerDecl = .{
135 .layout_token = null,
136 .ast = .{
137 .main_token = undefined,
138 .enum_token = null,
139 .members = tree.rootDecls(),
140 .arg = 0,
141 },
142 };
143134 if (AstGen.structDeclInner(
144135 &gen_scope,
145136 &gen_scope.base,
146137 0,
147 container_decl,
138 tree.containerDeclRoot(),
148139 .Auto,
149140 )) |struct_decl_ref| {
150141 assert(refToIndex(struct_decl_ref).? == 0);
src/Module.zig+2
......@@ -935,6 +935,8 @@ pub const Struct = struct {
935935 .tagged_union_enum_tag_trailing,
936936 => return queryFieldSrc(tree.*, query, file, tree.taggedUnionEnumTag(node)),
937937
938 .root => return queryFieldSrc(tree.*, query, file, tree.containerDeclRoot()),
939
938940 else => unreachable,
939941 }
940942 }