| author | |
| committer | |
| log | 96a5f7c8edac4bb2f50bdfe31c1287207d90d29b |
| tree | 714e07743f7c52820b2de8263f0f476409a2ee73 |
| parent | c085c6ecdd4b9436955ba2bb38f829100ed9b33d |
2 files changed, 20 insertions(+), 0 deletions(-)
src/Sema.zig+6| ... | ... | @@ -8657,6 +8657,12 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8657 | 8657 | return Air.internedToRef((try mod.getCoerced(int_val, dest_ty)).toIntern()); |
| 8658 | 8658 | } |
| 8659 | 8659 | |
| 8660 | if (dest_ty.intTagType(mod).zigTypeTag(mod) == .ComptimeInt) { | |
| 8661 | return sema.failWithNeededComptime(block, operand_src, .{ | |
| 8662 | .needed_comptime_reason = "value being casted to enum with 'comptime_int' tag type must be comptime-known", | |
| 8663 | }); | |
| 8664 | } | |
| 8665 | ||
| 8660 | 8666 | if (try sema.typeHasOnePossibleValue(dest_ty)) |opv| { |
| 8661 | 8667 | const result = Air.internedToRef(opv.toIntern()); |
| 8662 | 8668 | // The operand is runtime-known but the result is comptime-known. In |
test/cases/compile_errors/enum_backed_by_comptime_int_must_be_casted_from_comptime_value.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | export fn entry() void { | |
| 2 | const Tag = enum(comptime_int) { a, b }; | |
| 3 | ||
| 4 | var v: u32 = 0; | |
| 5 | _ = &v; | |
| 6 | _ = @as(Tag, @enumFromInt(v)); | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage2 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // :6:31: error: unable to resolve comptime value | |
| 14 | // :6:31: note: value being casted to enum with 'comptime_int' tag type must be comptime-known |