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 {...@@ -1722,8 +1722,16 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {
1722 for (decls) |src_decl, decl_i| {1722 for (decls) |src_decl, decl_i| {
1723 if (src_decl.cast(ast.Node.FnProto)) |fn_proto| {1723 if (src_decl.cast(ast.Node.FnProto)) |fn_proto| {
1724 // We will create a Decl for it regardless of analysis status.1724 // We will create a Decl for it regardless of analysis status.
1725 const name_tok = fn_proto.name_token orelse1725 const name_tok = fn_proto.name_token orelse {
1726 @panic("TODO handle missing function name in the parser");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
1727 const name_loc = tree.token_locs[name_tok];1735 const name_loc = tree.token_locs[name_tok];
1728 const name = tree.tokenSliceLoc(name_loc);1736 const name = tree.tokenSliceLoc(name_loc);
1729 const name_hash = root_scope.fullyQualifiedNameHash(name);1737 const name_hash = root_scope.fullyQualifiedNameHash(name);
...@@ -1734,6 +1742,7 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {...@@ -1734,6 +1742,7 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {
1734 // have been re-ordered.1742 // have been re-ordered.
1735 decl.src_index = decl_i;1743 decl.src_index = decl_i;
1736 if (deleted_decls.remove(decl) == null) {1744 if (deleted_decls.remove(decl) == null) {
1745 decl.analysis = .sema_failure;
1737 const err_msg = try ErrorMsg.create(self.allocator, tree.token_locs[name_tok].start, "redefinition of '{}'", .{decl.name});1746 const err_msg = try ErrorMsg.create(self.allocator, tree.token_locs[name_tok].start, "redefinition of '{}'", .{decl.name});
1738 errdefer err_msg.destroy(self.allocator);1747 errdefer err_msg.destroy(self.allocator);
1739 try self.failed_decls.putNoClobber(decl, err_msg);1748 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 {...@@ -86,12 +86,18 @@ pub fn addCases(ctx: *TestContext) !void {
86 \\export fn entry() void {}86 \\export fn entry() void {}
87 );87 );
88 }88 }
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 }
89 // TODO: re-enable these tests.98 // TODO: re-enable these tests.
90 // https://github.com/ziglang/zig/issues/136499 // 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"});
95 //ctx.testCompileError(101 //ctx.testCompileError(
96 // \\comptime {102 // \\comptime {
97 // \\ return;103 // \\ return;