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:30:33-07:00
log04b801655cbd9b4f6f00027fc1f638b237890149
treeffe751fa99e752deb81fbe3206197900a46df9ae
parent21a5769afefb47553391ae1ef801f64a58253c33

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
...@@ -10168,9 +10167,9 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const ast....@@ -10168,9 +10167,9 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const ast.
10168 const tree = astgen.tree;10167 const tree = astgen.tree;
10169 const node_tags = tree.nodes.items(.tag);10168 const node_tags = tree.nodes.items(.tag);
10170 const main_tokens = tree.nodes.items(.main_token);10169 const main_tokens = tree.nodes.items(.main_token);
10170 const token_tags = tree.tokens.items(.tag);
10171 for (members) |member_node| {10171 for (members) |member_node| {
10172 const name_token = switch (node_tags[member_node]) {10172 const name_token = switch (node_tags[member_node]) {
10173 .fn_decl,
10174 .fn_proto_simple,10173 .fn_proto_simple,
10175 .fn_proto_multi,10174 .fn_proto_multi,
10176 .fn_proto_one,10175 .fn_proto_one,
...@@ -10181,6 +10180,17 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const ast....@@ -10181,6 +10180,17 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const ast.
10181 .aligned_var_decl,10180 .aligned_var_decl,
10182 => main_tokens[member_node] + 1,10181 => main_tokens[member_node] + 1,
1018310182
10183 .fn_decl => blk: {
10184 const ident = main_tokens[member_node] + 1;
10185 if (token_tags[ident] != .identifier) {
10186 switch (astgen.failNode(member_node, "missing function name", .{})) {
10187 error.AnalysisFail => continue,
10188 error.OutOfMemory => return error.OutOfMemory,
10189 }
10190 }
10191 break :blk ident;
10192 },
10193
10184 else => continue,10194 else => continue,
10185 };10195 };
1018610196