authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-01 11:29:14-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-01 11:29:14-07:00
log173db6eea6f7fd46c21e8e156c8437f9e2e7a710
tree20ab0fcd11720575e43e3eb68d3f4987e378260f
parent77516af118f219f9d73494c8a1d5df3e23672680

AstGen: fix "missing function name" error

scanDecls() made an incorrect assumption about all declarations having function names. The compile error for "missing function name" needed to go into scanDecls().

1 files changed, 14 insertions(+), 4 deletions(-)

src/AstGen.zig+14-4
...@@ -2878,9 +2878,8 @@ fn fnDecl(...@@ -2878,9 +2878,8 @@ fn fnDecl(
2878 const tree = astgen.tree;2878 const tree = astgen.tree;
2879 const token_tags = tree.tokens.items(.tag);2879 const token_tags = tree.tokens.items(.tag);
28802880
2881 const fn_name_token = fn_proto.name_token orelse {2881 // missing function name already happened in scanDecls()
2882 return astgen.failTok(fn_proto.ast.fn_token, "missing function name", .{});2882 const fn_name_token = fn_proto.name_token orelse return error.AnalysisFail;
2883 };
2884 const fn_name_str_index = try astgen.identAsString(fn_name_token);2883 const fn_name_str_index = try astgen.identAsString(fn_name_token);
28852884
2886 // We insert this at the beginning so that its instruction index marks the2885 // We insert this at the beginning so that its instruction index marks the
...@@ -10145,9 +10144,9 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const ast....@@ -10145,9 +10144,9 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const ast.
10145 const tree = astgen.tree;10144 const tree = astgen.tree;
10146 const node_tags = tree.nodes.items(.tag);10145 const node_tags = tree.nodes.items(.tag);
10147 const main_tokens = tree.nodes.items(.main_token);10146 const main_tokens = tree.nodes.items(.main_token);
10147 const token_tags = tree.tokens.items(.tag);
10148 for (members) |member_node| {10148 for (members) |member_node| {
10149 const name_token = switch (node_tags[member_node]) {10149 const name_token = switch (node_tags[member_node]) {
10150 .fn_decl,
10151 .fn_proto_simple,10150 .fn_proto_simple,
10152 .fn_proto_multi,10151 .fn_proto_multi,
10153 .fn_proto_one,10152 .fn_proto_one,
...@@ -10158,6 +10157,17 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const ast....@@ -10158,6 +10157,17 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const ast.
10158 .aligned_var_decl,10157 .aligned_var_decl,
10159 => main_tokens[member_node] + 1,10158 => main_tokens[member_node] + 1,
1016010159
10160 .fn_decl => blk: {
10161 const ident = main_tokens[member_node] + 1;
10162 if (token_tags[ident] != .identifier) {
10163 switch (astgen.failNode(member_node, "missing function name", .{})) {
10164 error.AnalysisFail => continue,
10165 error.OutOfMemory => return error.OutOfMemory,
10166 }
10167 }
10168 break :blk ident;
10169 },
10170
10161 else => continue,10171 else => continue,
10162 };10172 };
1016310173