diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-12-30 15:40:11 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-01-15 15:11:36 -0800 |
| commit | 5b18af85cb77d8dd7b2300bd01c00990d03abde2 (patch) | |
| tree | 1de9ca1604f82d222a15fba0b0f58bbc466f047c /src/link.zig | |
| parent | a4895f3c42e8bd7d3eba5624e4a11aae5312a085 (diff) | |
| download | zig-5b18af85cb77d8dd7b2300bd01c00990d03abde2.tar.gz zig-5b18af85cb77d8dd7b2300bd01c00990d03abde2.zip | |
type checking for synthetic functions
Diffstat (limited to 'src/link.zig')
| -rw-r--r-- | src/link.zig | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/link.zig b/src/link.zig index 17ccb8ac0c..0a3d6f0bb1 100644 --- a/src/link.zig +++ b/src/link.zig @@ -214,22 +214,35 @@ pub const Diags = struct { return error.LinkFailure; } + pub fn failSourceLocation(diags: *Diags, sl: SourceLocation, comptime format: []const u8, args: anytype) error{LinkFailure} { + @branchHint(.cold); + addErrorSourceLocation(diags, sl, format, args); + return error.LinkFailure; + } + pub fn addError(diags: *Diags, comptime format: []const u8, args: anytype) void { + return addErrorSourceLocation(diags, .none, format, args); + } + + pub fn addErrorSourceLocation(diags: *Diags, sl: SourceLocation, comptime format: []const u8, args: anytype) void { @branchHint(.cold); const gpa = diags.gpa; const eu_main_msg = std.fmt.allocPrint(gpa, format, args); diags.mutex.lock(); defer diags.mutex.unlock(); - addErrorLockedFallible(diags, eu_main_msg) catch |err| switch (err) { + addErrorLockedFallible(diags, sl, eu_main_msg) catch |err| switch (err) { error.OutOfMemory => diags.setAllocFailureLocked(), }; } - fn addErrorLockedFallible(diags: *Diags, eu_main_msg: Allocator.Error![]u8) Allocator.Error!void { + fn addErrorLockedFallible(diags: *Diags, sl: SourceLocation, eu_main_msg: Allocator.Error![]u8) Allocator.Error!void { const gpa = diags.gpa; const main_msg = try eu_main_msg; errdefer gpa.free(main_msg); - try diags.msgs.append(gpa, .{ .msg = main_msg }); + try diags.msgs.append(gpa, .{ + .msg = main_msg, + .source_location = sl, + }); } pub fn addErrorWithNotes(diags: *Diags, note_count: usize) error{OutOfMemory}!ErrorWithNotes { |
