aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorPavel Verigo <paul.verigo@gmail.com>2024-01-28 17:15:33 +0100
committerVeikka Tuominen <git@vexu.eu>2024-01-29 01:43:19 +0200
commit96a5f7c8edac4bb2f50bdfe31c1287207d90d29b (patch)
tree714e07743f7c52820b2de8263f0f476409a2ee73 /src/Sema.zig
parentc085c6ecdd4b9436955ba2bb38f829100ed9b33d (diff)
downloadzig-96a5f7c8edac4bb2f50bdfe31c1287207d90d29b.tar.gz
zig-96a5f7c8edac4bb2f50bdfe31c1287207d90d29b.zip
Sema: fix casting runtime value to enum with comptime int tag type
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index e52a795314..af3e3700d7 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -8657,6 +8657,12 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
return Air.internedToRef((try mod.getCoerced(int_val, dest_ty)).toIntern());
}
+ if (dest_ty.intTagType(mod).zigTypeTag(mod) == .ComptimeInt) {
+ return sema.failWithNeededComptime(block, operand_src, .{
+ .needed_comptime_reason = "value being casted to enum with 'comptime_int' tag type must be comptime-known",
+ });
+ }
+
if (try sema.typeHasOnePossibleValue(dest_ty)) |opv| {
const result = Air.internedToRef(opv.toIntern());
// The operand is runtime-known but the result is comptime-known. In