aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-07 21:04:55 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-07 21:04:55 -0700
commitb67378fb08fb3129b66385479a278a93940f09f5 (patch)
tree337925698e538c1ea5646e0f75175844fc232dca /src
parenta62e19ec8ea4afcaf31a27dd32fab195a12a4877 (diff)
downloadzig-b67378fb08fb3129b66385479a278a93940f09f5.tar.gz
zig-b67378fb08fb3129b66385479a278a93940f09f5.zip
Sema: `@intToEnum` error msg includes a "declared here" hint
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 655fc4bd06..134e569948 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -1983,9 +1983,23 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr
if (try sema.resolveDefinedValue(block, operand_src, operand)) |int_val| {
if (!dest_ty.enumHasInt(int_val, target)) {
- return mod.fail(&block.base, src, "enum '{}' has no tag with value {}", .{
- dest_ty, int_val,
- });
+ const msg = msg: {
+ const msg = try mod.errMsg(
+ &block.base,
+ src,
+ "enum '{}' has no tag with value {}",
+ .{ dest_ty, int_val },
+ );
+ errdefer msg.destroy(sema.gpa);
+ try mod.errNoteNonLazy(
+ dest_ty.declSrcLoc(),
+ msg,
+ "enum declared here",
+ .{},
+ );
+ break :msg msg;
+ };
+ return mod.failWithOwnedErrorMsg(&block.base, msg);
}
return mod.constInst(arena, src, .{
.ty = dest_ty,