diff --git a/src/ir.cpp b/src/ir.cpp index cdf11f1801..350459db23 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -20254,6 +20254,11 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count, codegen->is_big_endian); return; + case ZigTypeIdEnum: + bigint_write_twos_complement(&val->data.x_enum_tag, buf, + val->type->data.enumeration.tag_int_type->data.integral.bit_count, + codegen->is_big_endian); + return; case ZigTypeIdFloat: float_write_ieee597(val, buf, codegen->is_big_endian); return; @@ -20285,8 +20290,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue zig_panic("TODO buf_write_value_bytes error union"); case ZigTypeIdErrorSet: zig_panic("TODO buf_write_value_bytes pure error type"); - case ZigTypeIdEnum: - zig_panic("TODO buf_write_value_bytes enum type"); case ZigTypeIdFn: zig_panic("TODO buf_write_value_bytes fn type"); case ZigTypeIdUnion: diff --git a/test/cases/bitcast.zig b/test/cases/bitcast.zig index 878140954a..0857f88e57 100644 --- a/test/cases/bitcast.zig +++ b/test/cases/bitcast.zig @@ -16,3 +16,20 @@ fn conv(x: i32) u32 { fn conv2(x: u32) i32 { return @bitCast(i32, x); } + +test "@bitCast extern enum to its integer type" { + const SOCK = extern enum { + A, + B, + + fn testBitCastExternEnum() void { + var SOCK_DGRAM = @This().B; + var sock_dgram = @bitCast(c_int, SOCK_DGRAM); + assert(sock_dgram == 1); + } + }; + + SOCK.testBitCastExternEnum(); + comptime SOCK.testBitCastExternEnum(); +} +