missing 'defined here' notes on equality compile error
Zig Version
0.12.0-dev.1828+225fe6ddb
Steps to Reproduce and Observed Behavior
const std = @import("std");
const E = enum(u32) {
a,
b,
c,
_,
};
const S = struct {
a: u32,
b: u32,
c: u32,
};
test {
var x: S = std.mem.zeroes(S);
_ = &x;
var y: bool = x.a == E.b;
_ = &y;
}
test.zig:20:23: error: incompatible types: 'u32' and 'test.E'
var y: bool = x.a == E.b;
~~~~^~~~~~
test.zig:20:20: note: type 'u32' here
var y: bool = x.a == E.b;
~^~
test.zig:20:27: note: type 'test.E' here
var y: bool = x.a == E.b;
~^~
Expected Behavior
same as above but with the addition of test.zig:10:1: note: 'S' defined here and test.zig:3:1: note: 'E' defined here
(oops, meant to file this under error message)
I see no purpose in providing a "defined here" note. The error message is focused on the fact that you cannot compare u32 to an enum. Which enum is at fault has nothing to do with it.
perhaps, but the u32 came from a struct field and i might wanna go update the type of that field, which isnt trivial to know which one in a case where S is from a generic function. this was a reduction after all.
I found a small addition that can partially address this issue. Unfortunately, for the example above it only adds a note for the source location of E.
Output with additional note:
src/main.zig:20:23: error: incompatible types: 'u32' and 'main.E'
var y: bool = x.a == E.b;
~~~~^~~~~~
src/main.zig:20:20: note: type 'u32' here
var y: bool = x.a == E.b;
~^~
src/main.zig:20:27: note: type 'main.E' here
var y: bool = x.a == E.b;
~^~
src/main.zig:3:11: note: type 'main.E' declared here
const E = enum(u32) {
^~~~
Diff
diff --git a/src/Sema.zig b/src/Sema.zig
index e9b6615f14..1ddf3244b8 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -33909,7 +33909,20 @@ const PeerResolveResult = union(enum) {
};
if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(pt)});
+ if (conflict_tys[conflict_idx[0]].srcLocOrNull(pt.zcu)) |loc| try sema.errNote(
+ loc,
+ msg,
+ "type '{}' declared here",
+ .{conflict_tys[0].fmt(pt)},
+ );
+
if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(pt)});
+ if (conflict_tys[conflict_idx[1]].srcLocOrNull(pt.zcu)) |loc| try sema.errNote(
+ loc,
+ msg,
+ "type '{}' declared here",
+ .{conflict_tys[1].fmt(pt)},
+ );
// No child error
break;