aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-06-30 17:38:04 +0300
committerVeikka Tuominen <git@vexu.eu>2022-07-01 10:22:25 +0300
commite6ebf56dd6cf2e2c23af952d2e9e327703c9cd02 (patch)
tree5034cb50152f234c3dce7ad746e1f7c7af5fef9c /src/Sema.zig
parentae7b32eb62cb00a09fe2e0e30b307eb83e9f0a86 (diff)
downloadzig-e6ebf56dd6cf2e2c23af952d2e9e327703c9cd02.tar.gz
zig-e6ebf56dd6cf2e2c23af952d2e9e327703c9cd02.zip
Sema: validate `@intToEnum` int operand type
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 0e7188a6c9..64db6a9bed 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -2439,9 +2439,9 @@ fn zirEnumDecl(
const field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, field_i);
const other_tag_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, gop.index);
const msg = msg: {
- const msg = try sema.errMsg(block, field_src, "duplicate enum tag", .{});
+ const msg = try sema.errMsg(block, field_src, "duplicate enum field '{s}'", .{field_name});
errdefer msg.destroy(gpa);
- try sema.errNote(block, other_tag_src, msg, "other tag here", .{});
+ try sema.errNote(block, other_tag_src, msg, "other field here", .{});
break :msg msg;
};
return sema.failWithOwnedErrorMsg(block, msg);
@@ -2751,7 +2751,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
const src = inst_data.src();
const operand_ty = sema.typeOf(operand);
switch (operand_ty.zigTypeTag()) {
- .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is discarded", .{}),
+ .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is discardederror is discarded. consider using `try`, `catch`, or `if`", .{}),
else => return,
}
}
@@ -6444,6 +6444,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
if (dest_ty.zigTypeTag() != .Enum) {
return sema.fail(block, dest_ty_src, "expected enum, found '{}'", .{dest_ty.fmt(sema.mod)});
}
+ _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand));
if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |int_val| {
if (dest_ty.isNonexhaustiveEnum()) {