From 1a1624ebc7ff4090d55479bdf4e5fe618da6a091 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 30 Aug 2021 03:52:56 -0700 Subject: [PATCH] fix `test-stage2` --- src/AstGen.zig | 2 ++ test/compile_errors.zig | 13 ++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index f5531c6ab613..c24b447016e7 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -10144,6 +10144,7 @@ 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, @@ -10174,6 +10175,7 @@ fn scanDecls(astgen: *AstGen, namespace: *Scope.Namespace, members: []const ast. } } + if (token_tags[name_token] != .identifier) return astgen.failNode(member_node, "missing function name", .{}); const name_str_index = try astgen.identAsString(name_token); const gop = try namespace.decls.getOrPut(gpa, name_str_index); if (gop.found_existing) { diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 707277364b2b..1e71ce141e81 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -4975,7 +4975,6 @@ pub fn addCases(ctx: *TestContext) !void { \\fn b() void {} , &[_][]const u8{ "tmp.zig:3:6: error: unreachable code", - "tmp.zig:2:5: note: control flow is diverted here", }); ctx.objErrStage1("bad import", @@ -5045,8 +5044,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ const a = return; \\} , &[_][]const u8{ - "tmp.zig:2:5: error: unreachable code", - "tmp.zig:2:15: note: control flow is diverted here", + "tmp.zig:2:15: error: unreachable code", }); ctx.objErrStage1("unreachable variable", @@ -5281,8 +5279,7 @@ pub fn addCases(ctx: *TestContext) !void { \\} \\export fn entry() void { _ = f(); } , &[_][]const u8{ - "tmp.zig:2:12: error: unreachable code", - "tmp.zig:2:21: note: control flow is diverted here", + "tmp.zig:2:21: error: unreachable code", }); ctx.objErrStage1("invalid builtin fn", @@ -7458,8 +7455,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ var z: noreturn = return; \\} , &[_][]const u8{ - "tmp.zig:2:5: error: unreachable code", - "tmp.zig:2:23: note: control flow is diverted here", + "tmp.zig:2:23: error: unreachable code", }); ctx.objErrStage1("wrong types given to atomic order args in cmpxchg", @@ -7657,8 +7653,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ var allocator: ContextAllocator = undefined; \\} , &[_][]const u8{ - "tmp.zig:4:5: error: unreachable code", - "tmp.zig:4:25: note: control flow is diverted here", + "tmp.zig:4:25: error: unreachable code", "tmp.zig:12:9: error: unused local variable", });