mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
Sema: fix casting runtime value to enum with comptime int tag type
This commit is contained in:
parent
c085c6ecdd
commit
96a5f7c8ed
@ -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
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
export fn entry() void {
|
||||
const Tag = enum(comptime_int) { a, b };
|
||||
|
||||
var v: u32 = 0;
|
||||
_ = &v;
|
||||
_ = @as(Tag, @enumFromInt(v));
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :6:31: error: unable to resolve comptime value
|
||||
// :6:31: note: value being casted to enum with 'comptime_int' tag type must be comptime-known
|
||||
Loading…
x
Reference in New Issue
Block a user