Stage2: handle missing function names
This commit is contained in:
@@ -1722,8 +1722,16 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {
|
||||
for (decls) |src_decl, decl_i| {
|
||||
if (src_decl.cast(ast.Node.FnProto)) |fn_proto| {
|
||||
// We will create a Decl for it regardless of analysis status.
|
||||
const name_tok = fn_proto.name_token orelse
|
||||
@panic("TODO handle missing function name in the parser");
|
||||
const name_tok = fn_proto.name_token orelse {
|
||||
const err_msg = try ErrorMsg.create(self.allocator, tree.token_locs[fn_proto.firstToken()].end, "missing function name", .{});
|
||||
// TODO: cache a single invalid decl in the Module?
|
||||
const new_decl = try self.createNewDecl(&root_scope.base, "", decl_i, [1]u8{0} ** 16, [1]u8{0} ** 16);
|
||||
root_scope.decls.appendAssumeCapacity(new_decl);
|
||||
errdefer err_msg.destroy(self.allocator);
|
||||
try self.failed_decls.putNoClobber(new_decl, err_msg);
|
||||
continue;
|
||||
};
|
||||
|
||||
const name_loc = tree.token_locs[name_tok];
|
||||
const name = tree.tokenSliceLoc(name_loc);
|
||||
const name_hash = root_scope.fullyQualifiedNameHash(name);
|
||||
@@ -1734,6 +1742,7 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void {
|
||||
// have been re-ordered.
|
||||
decl.src_index = decl_i;
|
||||
if (deleted_decls.remove(decl) == null) {
|
||||
decl.analysis = .sema_failure;
|
||||
const err_msg = try ErrorMsg.create(self.allocator, tree.token_locs[name_tok].start, "redefinition of '{}'", .{decl.name});
|
||||
errdefer err_msg.destroy(self.allocator);
|
||||
try self.failed_decls.putNoClobber(decl, err_msg);
|
||||
|
||||
Reference in New Issue
Block a user