aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDominic <4678790+dweiller@users.noreply.github.com>2023-05-08 17:59:06 +1000
committerGitHub <noreply@github.com>2023-05-08 10:59:06 +0300
commit5a3eca5d4ca42f92abe60040e21ffd8e307d8466 (patch)
treea69d1c9ccff1feeb63f6117658695703f682ccd4 /src
parentbac3a28214d07f761e25fcc12a6708f70c8ccc01 (diff)
downloadzig-5a3eca5d4ca42f92abe60040e21ffd8e307d8466.tar.gz
zig-5a3eca5d4ca42f92abe60040e21ffd8e307d8466.zip
Disallow named test decls with duplicate names
Diffstat (limited to 'src')
-rw-r--r--src/Module.zig26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 538c716bc3..6a33990463 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -5280,6 +5280,9 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
}
},
};
+ var must_free_decl_name = true;
+ defer if (must_free_decl_name) gpa.free(decl_name);
+
const is_exported = export_bit and decl_name_index != 0;
if (kind == .@"usingnamespace") try namespace.usingnamespace_set.ensureUnusedCapacity(gpa, 1);
@@ -5296,6 +5299,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
const new_decl = mod.declPtr(new_decl_index);
new_decl.kind = kind;
new_decl.name = decl_name;
+ must_free_decl_name = false;
if (kind == .@"usingnamespace") {
namespace.usingnamespace_set.putAssumeCapacity(new_decl_index, is_pub);
}
@@ -5339,9 +5343,29 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
new_decl.alive = true; // This Decl corresponds to an AST node and therefore always alive.
return;
}
- gpa.free(decl_name);
const decl_index = gop.key_ptr.*;
const decl = mod.declPtr(decl_index);
+ if (kind == .@"test") {
+ const src_loc = SrcLoc{
+ .file_scope = decl.getFileScope(),
+ .parent_decl_node = decl.src_node,
+ .lazy = .{ .token_offset = 1 },
+ };
+ const msg = try ErrorMsg.create(
+ gpa,
+ src_loc,
+ "found test declaration with duplicate name: {s}",
+ .{decl_name},
+ );
+ errdefer msg.destroy(gpa);
+ try mod.failed_decls.putNoClobber(gpa, decl_index, msg);
+ const other_src_loc = SrcLoc{
+ .file_scope = namespace.file_scope,
+ .parent_decl_node = decl_node,
+ .lazy = .{ .token_offset = 1 },
+ };
+ try mod.errNoteNonLazy(other_src_loc, msg, "other test here", .{});
+ }
log.debug("scan existing {*} ({s}) of {*}", .{ decl, decl.name, namespace });
// Update the AST node of the decl; even if its contents are unchanged, it may
// have been re-ordered.