aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-08-12 13:22:27 -0400
committerGitHub <noreply@github.com>2021-08-12 13:22:27 -0400
commita0670e748ec4914f7fc198422d0815e71e90a54f (patch)
tree4f32c8520102c445752ba882657fb7e9a67854c8 /src/Module.zig
parent394d287778971c3d06fc401e688fc048cdf9860a (diff)
parent16c11988587ad78cd47ec571e1120c052abd47ed (diff)
downloadzig-a0670e748ec4914f7fc198422d0815e71e90a54f.tar.gz
zig-a0670e748ec4914f7fc198422d0815e71e90a54f.zip
Merge pull request #9166 from joachimschmidt557/stage2
stage2 Sema: Add error notes to unresolvable peer types
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();