From 04b801655cbd9b4f6f00027fc1f638b237890149 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 1 Sep 2021 11:29:14 -0700 Subject: [PATCH] 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(). --- src/AstGen.zig | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index 75f506096f0e649340c5238117cfc6690d8b982d..245e40c3a1c34f9394e74b44403986288fe406c5 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -2878,9 +2878,8 @@ fn fnDecl( const tree = astgen.tree; const token_tags = tree.tokens.items(.tag); - const fn_name_token = fn_proto.name_token orelse { - return astgen.failTok(fn_proto.ast.fn_token, "missing function name", .{}); - }; + // missing function name already happened in scanDecls() + const fn_name_token = fn_proto.name_token orelse return error.AnalysisFail; const fn_name_str_index = try astgen.identAsString(fn_name_token); // 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. const tree = astgen.tree; const node_tags = tree.nodes.items(.tag); const main_tokens = tree.nodes.items(.main_token); + const token_tags = tree.tokens.items(.tag); for (members) |member_node| { const name_token = switch (node_tags[member_node]) { - .fn_decl, .fn_proto_simple, .fn_proto_multi, .fn_proto_one, @@ -10181,6 +10180,17 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const ast. .aligned_var_decl, => main_tokens[member_node] + 1, + .fn_decl => blk: { + const ident = main_tokens[member_node] + 1; + if (token_tags[ident] != .identifier) { + switch (astgen.failNode(member_node, "missing function name", .{})) { + error.AnalysisFail => continue, + error.OutOfMemory => return error.OutOfMemory, + } + } + break :blk ident; + }, + else => continue, }; -- 2.54.0