| ... | @@ -4128,6 +4128,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void | ... | @@ -4128,6 +4128,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4128 | .@"comptime" => info: { | 4128 | .@"comptime" => info: { |
| 4129 | const i = iter.comptime_index; | 4129 | const i = iter.comptime_index; |
| 4130 | iter.comptime_index += 1; | 4130 | iter.comptime_index += 1; |
| | 4131 | // TODO: avoid collisions with named decls with this name |
| 4131 | break :info .{ | 4132 | break :info .{ |
| 4132 | try ip.getOrPutStringFmt(gpa, "comptime_{d}", .{i}), | 4133 | try ip.getOrPutStringFmt(gpa, "comptime_{d}", .{i}), |
| 4133 | .@"comptime", | 4134 | .@"comptime", |
| ... | @@ -4137,6 +4138,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void | ... | @@ -4137,6 +4138,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4137 | .@"usingnamespace" => info: { | 4138 | .@"usingnamespace" => info: { |
| 4138 | const i = iter.usingnamespace_index; | 4139 | const i = iter.usingnamespace_index; |
| 4139 | iter.usingnamespace_index += 1; | 4140 | iter.usingnamespace_index += 1; |
| | 4141 | // TODO: avoid collisions with named decls with this name |
| 4140 | break :info .{ | 4142 | break :info .{ |
| 4141 | try ip.getOrPutStringFmt(gpa, "usingnamespace_{d}", .{i}), | 4143 | try ip.getOrPutStringFmt(gpa, "usingnamespace_{d}", .{i}), |
| 4142 | .@"usingnamespace", | 4144 | .@"usingnamespace", |
| ... | @@ -4146,6 +4148,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void | ... | @@ -4146,6 +4148,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4146 | .unnamed_test => info: { | 4148 | .unnamed_test => info: { |
| 4147 | const i = iter.unnamed_test_index; | 4149 | const i = iter.unnamed_test_index; |
| 4148 | iter.unnamed_test_index += 1; | 4150 | iter.unnamed_test_index += 1; |
| | 4151 | // TODO: avoid collisions with named decls with this name |
| 4149 | break :info .{ | 4152 | break :info .{ |
| 4150 | try ip.getOrPutStringFmt(gpa, "test_{d}", .{i}), | 4153 | try ip.getOrPutStringFmt(gpa, "test_{d}", .{i}), |
| 4151 | .@"test", | 4154 | .@"test", |
| ... | @@ -4155,6 +4158,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void | ... | @@ -4155,6 +4158,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4155 | .decltest => info: { | 4158 | .decltest => info: { |
| 4156 | assert(declaration.flags.has_doc_comment); | 4159 | assert(declaration.flags.has_doc_comment); |
| 4157 | const name = zir.nullTerminatedString(@enumFromInt(zir.extra[extra.end])); | 4160 | const name = zir.nullTerminatedString(@enumFromInt(zir.extra[extra.end])); |
| | 4161 | // TODO: avoid collisions with named decls with this name |
| 4158 | break :info .{ | 4162 | break :info .{ |
| 4159 | try ip.getOrPutStringFmt(gpa, "decltest.{s}", .{name}), | 4163 | try ip.getOrPutStringFmt(gpa, "decltest.{s}", .{name}), |
| 4160 | .@"test", | 4164 | .@"test", |
| ... | @@ -4162,6 +4166,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void | ... | @@ -4162,6 +4166,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4162 | }; | 4166 | }; |
| 4163 | }, | 4167 | }, |
| 4164 | _ => if (declaration.name.isNamedTest(zir)) .{ | 4168 | _ => if (declaration.name.isNamedTest(zir)) .{ |
| | 4169 | // TODO: avoid collisions with named decls with this name |
| 4165 | try ip.getOrPutStringFmt(gpa, "test.{s}", .{zir.nullTerminatedString(declaration.name.toString(zir).?)}), | 4170 | try ip.getOrPutStringFmt(gpa, "test.{s}", .{zir.nullTerminatedString(declaration.name.toString(zir).?)}), |
| 4166 | .@"test", | 4171 | .@"test", |
| 4167 | true, | 4172 | true, |
| ... | @@ -4226,24 +4231,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void | ... | @@ -4226,24 +4231,6 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4226 | } | 4231 | } |
| 4227 | const decl_index = gop.key_ptr.*; | 4232 | const decl_index = gop.key_ptr.*; |
| 4228 | const decl = zcu.declPtr(decl_index); | 4233 | const decl = zcu.declPtr(decl_index); |
| 4229 | if (kind == .@"test") { | | |
| 4230 | const src_loc = SrcLoc{ | | |
| 4231 | .file_scope = decl.getFileScope(zcu), | | |
| 4232 | .parent_decl_node = decl.src_node, | | |
| 4233 | .lazy = .{ .token_offset = 1 }, | | |
| 4234 | }; | | |
| 4235 | const msg = try ErrorMsg.create(gpa, src_loc, "duplicate test name: {}", .{ | | |
| 4236 | decl_name.fmt(ip), | | |
| 4237 | }); | | |
| 4238 | errdefer msg.destroy(gpa); | | |
| 4239 | try zcu.failed_decls.putNoClobber(gpa, decl_index, msg); | | |
| 4240 | const other_src_loc = SrcLoc{ | | |
| 4241 | .file_scope = namespace.file_scope, | | |
| 4242 | .parent_decl_node = decl_node, | | |
| 4243 | .lazy = .{ .token_offset = 1 }, | | |
| 4244 | }; | | |
| 4245 | try zcu.errNoteNonLazy(other_src_loc, msg, "other test here", .{}); | | |
| 4246 | } | | |
| 4247 | // Update the AST node of the decl; even if its contents are unchanged, it may | 4234 | // Update the AST node of the decl; even if its contents are unchanged, it may |
| 4248 | // have been re-ordered. | 4235 | // have been re-ordered. |
| 4249 | decl.src_node = decl_node; | 4236 | decl.src_node = decl_node; |