aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig
index 42b36b5a04..319363e9b8 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -4399,6 +4399,57 @@ pub const SwitchProngSrc = union(enum) {
}
};
+pub const PeerTypeCandidateSrc = union(enum) {
+ /// Do not print out error notes for candidate sources
+ none: void,
+ /// When we want to know the the src of candidate i, look up at
+ /// index i in this slice
+ override: []LazySrcLoc,
+ /// resolvePeerTypes originates from a @TypeOf(...) call
+ typeof_builtin_call_node_offset: i32,
+
+ pub fn resolve(
+ self: PeerTypeCandidateSrc,
+ gpa: *Allocator,
+ decl: *Decl,
+ candidates: usize,
+ candidate_i: usize,
+ ) ?LazySrcLoc {
+ @setCold(true);
+
+ switch (self) {
+ .none => {
+ return null;
+ },
+ .override => |candidate_srcs| {
+ return candidate_srcs[candidate_i];
+ },
+ .typeof_builtin_call_node_offset => |node_offset| {
+ if (candidates <= 2) {
+ switch (candidate_i) {
+ 0 => return LazySrcLoc{ .node_offset_builtin_call_arg0 = node_offset },
+ 1 => return LazySrcLoc{ .node_offset_builtin_call_arg1 = node_offset },
+ else => unreachable,
+ }
+ }
+
+ const tree = decl.namespace.file_scope.getTree(gpa) catch |err| {
+ // In this case we emit a warning + a less precise source location.
+ log.warn("unable to load {s}: {s}", .{
+ decl.namespace.file_scope.sub_file_path, @errorName(err),
+ });
+ return LazySrcLoc{ .node_offset = 0 };
+ };
+ const node = decl.relativeToNodeIndex(node_offset);
+ const node_datas = tree.nodes.items(.data);
+ const params = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs];
+
+ return LazySrcLoc{ .node_abs = params[candidate_i] };
+ },
+ }
+ }
+};
+
pub fn analyzeStructFields(mod: *Module, struct_obj: *Struct) CompileError!void {
const tracy = trace(@src());
defer tracy.end();