authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-26 04:03:54-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-06-26 04:05:41-04:00
log6510888039baaa0058a7e2bade2750569af1abbd
tree1c2254e5d22d4e2d72b2f21c78094589689d0baf
parent4a17e008daa90d5dbb0fc917d53e52c1ec990f2d
signaturelock-open Commit is signed but in an unrecognized format.

Stage2: function redefinition detection for Zig code


2 files changed, 28 insertions(+), 9 deletions(-)

src-self-hosted/Module.zig+9-4
......@@ -1733,10 +1733,15 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {
17331733 // Update the AST Node index of the decl, even if its contents are unchanged, it may
17341734 // have been re-ordered.
17351735 decl.src_index = decl_i;
1736 deleted_decls.removeAssertDiscard(decl);
1737 if (!srcHashEql(decl.contents_hash, contents_hash)) {
1738 try self.markOutdatedDecl(decl);
1739 decl.contents_hash = contents_hash;
1736 if (deleted_decls.remove(decl) == null) {
1737 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);
1739 try self.failed_decls.putNoClobber(decl, err_msg);
1740 } else {
1741 if (!srcHashEql(decl.contents_hash, contents_hash)) {
1742 try self.markOutdatedDecl(decl);
1743 decl.contents_hash = contents_hash;
1744 }
17401745 }
17411746 } else {
17421747 const new_decl = try self.createNewDecl(&root_scope.base, name, decl_i, name_hash, contents_hash);
test/stage2/compile_errors.zig+19-5
......@@ -67,14 +67,28 @@ pub fn addCases(ctx: *TestContext) !void {
6767 \\@1 = export(@0, "start")
6868 );
6969 }
70 // TODO: need to make sure this works with other variants of export.
71 // As is, the same error occurs without export.
72 {
73 var case = ctx.obj("exported symbol collision", linux_x64);
74 case.addError(
75 \\export fn entry() void {}
76 \\export fn entry() void {}
77 , &[_][]const u8{":2:11: error: redefinition of 'entry'"});
78 case.compiles(
79 \\export fn entry() void {}
80 );
81 case.addError(
82 \\fn entry() void {}
83 \\fn entry() void {}
84 , &[_][]const u8{":2:4: error: redefinition of 'entry'"});
85 case.compiles(
86 \\export fn entry() void {}
87 );
88 }
7089 // TODO: re-enable these tests.
7190 // https://github.com/ziglang/zig/issues/1364
7291
73 // ctx.compileError("Export same symbol twice", linux_x64,
74 // \\export fn entry() void {}
75 // \\export fn entry() void {}
76 // , &[_][]const u8{":2:1: error: exported symbol collision"});
77
7892 // ctx.addError("Missing function name", linux_x64, .Zig,
7993 // \\fn() void {}
8094 // , &[_][]const u8{":1:3: error: missing function name"});