aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorDavid Rubin <87927264+Rexicon226@users.noreply.github.com>2024-02-03 11:52:05 -0800
committerGitHub <noreply@github.com>2024-02-03 19:52:05 +0000
commit122387943bf1d00c85aba77f37c93072e43140c9 (patch)
tree9b2d270404d51c0a0d4f1c05b0302dae76270b57 /src/Sema.zig
parenteb4024036d3e8e0c4a8b0dcf09da107421f3fa01 (diff)
downloadzig-122387943bf1d00c85aba77f37c93072e43140c9.tar.gz
zig-122387943bf1d00c85aba77f37c93072e43140c9.zip
Fix OOB when enum field out of order in different file
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 35dc1089b6..e7f2677c8e 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -37125,7 +37125,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
const msg = msg: {
const ty_src = mod.fieldSrcLoc(union_type.decl, .{
.index = field_i,
- .range = .type,
+ .range = .name,
}).lazy;
const msg = try sema.errMsg(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{
field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod),
@@ -37136,6 +37136,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
};
return sema.failWithOwnedErrorMsg(&block_scope, msg);
};
+
// No check for duplicate because the check already happened in order
// to create the enum type in the first place.
assert(!explicit_tags_seen[enum_index]);
@@ -37146,14 +37147,15 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
const msg = msg: {
const ty_src = mod.fieldSrcLoc(union_type.decl, .{
.index = field_i,
- .range = .type,
+ .range = .name,
}).lazy;
const enum_field_src = mod.fieldSrcLoc(tag_info.decl, .{ .index = enum_index }).lazy;
const msg = try sema.errMsg(&block_scope, ty_src, "union field '{}' ordered differently than corresponding enum field", .{
field_name.fmt(ip),
});
errdefer msg.destroy(sema.gpa);
- try sema.errNote(&block_scope, enum_field_src, msg, "enum field here", .{});
+ const decl_ptr = mod.declPtr(tag_info.decl);
+ try mod.errNoteNonLazy(enum_field_src.toSrcLoc(decl_ptr, mod), msg, "enum field here", .{});
break :msg msg;
};
return sema.failWithOwnedErrorMsg(&block_scope, msg);