authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-26 04:36:17-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-26 04:36:17-04:00
logc8f60b2e2f15713754ac4b0911a7d13b6057264d
treeebd186d28320ceae0997cdb8b63e8af07bdc2b02
parent6510888039baaa0058a7e2bade2750569af1abbd
signaturelock-open Commit is signed but in an unrecognized format.

Stage2: handle missing function names


2 files changed, 20 insertions(+), 5 deletions(-)

src-self-hosted/Module.zig+11-2
......@@ -1722,8 +1722,16 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {
17221722 for (decls) |src_decl, decl_i| {
17231723 if (src_decl.cast(ast.Node.FnProto)) |fn_proto| {
17241724 // We will create a Decl for it regardless of analysis status.
1725 const name_tok = fn_proto.name_token orelse
1726 @panic("TODO handle missing function name in the parser");
1725 const name_tok = fn_proto.name_token orelse {
1726 const err_msg = try ErrorMsg.create(self.allocator, tree.token_locs[fn_proto.firstToken()].end, "missing function name", .{});
1727 // TODO: cache a single invalid decl in the Module?
1728 const new_decl = try self.createNewDecl(&root_scope.base, "", decl_i, [1]u8{0} ** 16, [1]u8{0} ** 16);
1729 root_scope.decls.appendAssumeCapacity(new_decl);
1730 errdefer err_msg.destroy(self.allocator);
1731 try self.failed_decls.putNoClobber(new_decl, err_msg);
1732 continue;
1733 };
1734
17271735 const name_loc = tree.token_locs[name_tok];
17281736 const name = tree.tokenSliceLoc(name_loc);
17291737 const name_hash = root_scope.fullyQualifiedNameHash(name);
......@@ -1734,6 +1742,7 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {
17341742 // have been re-ordered.
17351743 decl.src_index = decl_i;
17361744 if (deleted_decls.remove(decl) == null) {
1745 decl.analysis = .sema_failure;
17371746 const err_msg = try ErrorMsg.create(self.allocator, tree.token_locs[name_tok].start, "redefinition of '{}'", .{decl.name});
17381747 errdefer err_msg.destroy(self.allocator);
17391748 try self.failed_decls.putNoClobber(decl, err_msg);
test/stage2/compile_errors.zig+9-3
......@@ -86,12 +86,18 @@ pub fn addCases(ctx: *TestContext) !void {
8686 \\export fn entry() void {}
8787 );
8888 }
89 {
90 var case = ctx.obj("missing function name", linux_x64);
91 case.addError(
92 \\fn() void {}
93 , &[_][]const u8{":1:3: error: missing function name"});
94 case.compiles(
95 \\fn a() void {}
96 );
97 }
8998 // TODO: re-enable these tests.
9099 // https://github.com/ziglang/zig/issues/1364
91100
92 // ctx.addError("Missing function name", linux_x64, .Zig,
93 // \\fn() void {}
94 // , &[_][]const u8{":1:3: error: missing function name"});
95101 //ctx.testCompileError(
96102 // \\comptime {
97103 // \\ return;